I am using JSONObject plugin that is downloaded from Unify Community, I can decode the “max” value but I’m not able to decode the “score”, is there any solution to deserialize the score? Below is the response code:
WWW Ok!: {“max”:“5”,“data”:[{“class”:“com.abc.application”,“id”:1,“date”:“2015-08-19T09:00:00Z”,“job”:Teacher,“score”:30}]}
The following code should work (Using JSONFx 1.4)
(works similar with JSONObject and other JSON variants)
public static string FiletoJSON(object T)
{
try
{
StringBuilder sb = new StringBuilder();
JsonWriterSettings settings = JsonDataWriter.CreateSettings(true);
settings.TypeHintName = "__type";
JsonWriter writer = new JsonWriter(sb, settings);
writer.Write(T);
return sb.ToString();
}
catch(Exception e)
{
Debug.LogWarning(e.InnerException);
return null;
}
}
public static T JSONtoFile<T>(string JSONString)
{
try
{
JsonReaderSettings settings = JsonDataReader.CreateSettings(true);
settings.TypeHintName = "__type";
using (TextReader textReader = new StringReader(JSONString))
{
var jsonReader = new JsonReader(textReader, settings);
return jsonReader.Deserialize<T>();
}
}
catch (Exception e)
{
Debug.LogWarning(e);
return default(T);
}
}