TopShelfCustomer/TopShelfCustomer/Services/SerializationHelper.cs
/// <summary>
/// JsonReadField:
///
/// Static method to read and parse a json object from the static filepath.
/// Takes the filename and field name of the JSON object.
/// </summary>
/// <param name="filename"> The name of the file to read </param>
/// <param name="fieldname"> The field to read from the returned JSON object </param>
/// <returns> the field fetched from the JSON file and object (as a string) </returns>


Static method to read and parse a json object from the static filepath.
Takes the filename and field name of the JSON object.
Static method to read and parse a json object from the static filepath . Takes the filename and field name of the JSON object .
public static string JsonReadField ( string filename, string fieldname ) {
            try {
                var filepath = Path.Combine( FolderPath, filename + FileExtension );        
                var content = File.ReadAllText( filepath );     
                JObject obj = JObject.Parse( content );     
                return obj[fieldname].ToString();       
            } catch ( Exception e ) {
                Debug.WriteLine( e.Message );
                return null;
            }
        }
public static string JsonReadField ( string filename , string fieldname ) { try { var filepath = Path . Combine ( FolderPath , filename + FileExtension ) ; var content = File . ReadAllText ( filepath ) ; JObject obj = JObject . Parse ( content ) ; return obj [ fieldname ] . ToString ( ) ; } catch ( Exception e ) { Debug . WriteLine ( e . Message ) ; return null ; } }
JsonReadField:
JsonReadField :
//Create the file path //Read the entire json file //Parse the json text to an object //Return the value of the object for the passed fieldname
the field fetched from the JSON file and object (as a string)
the field fetched from the JSON file and object ( as a string )
filename
string
The name of the file to read
The name of the file to read
fieldname
string
The field to read from the returned JSON object
The field to read from the returned JSON object