TopShelfCustomer/TopShelfCustomer/Services/SerializationHelper.cs
/// <summary>
/// JsonRead:
///
/// Static method to read and parse a json object from the static filepath.
/// Takes the filename of the JSON object, reads the JSON, and
/// returns an object of the provided type.
/// </summary>
/// <param name="filename"> The name of the file to read </param>
/// <returns> an object (of type T) created from the fetched JSON </returns>


Static method to read and parse a json object from the static filepath.
Takes the filename of the JSON object, reads the JSON, and
returns an object of the provided type.
Static method to read and parse a json object from the static filepath . Takes the filename of the JSON object reads the JSON and returns an object of the provided type .
public static object JsonRead<T> ( string filename ) {
            try {
                var filepath = Path.Combine( FolderPath, filename + FileExtension );        
                var content = File.ReadAllText( filepath );     
                JObject obj = JObject.Parse( content );     
                return obj.ToObject<T>();       
            } catch ( Exception e ) {
                Debug.WriteLine( e.Message );
                return null;
            }
        }
public static object JsonRead < T > ( string filename ) { try { var filepath = Path . Combine ( FolderPath , filename + FileExtension ) ; var content = File . ReadAllText ( filepath ) ; JObject obj = JObject . Parse ( content ) ; return obj . ToObject < T > ( ) ; } catch ( Exception e ) { Debug . WriteLine ( e . Message ) ; return null ; } }
JsonRead:
JsonRead :
//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
an object (of type T) created from the fetched JSON
an object ( of type T ) created from the fetched JSON
filename
string
The name of the file to read
The name of the file to read