问题
I need to save a list of ParseObjects to disk in C#, and was wondering if anyone had any recommendations on how to achieve this.
I am sure that the Parse .NET SDK has a means of converting ParseObjects to/from JSON since that is the format used during transit to parse server, but I haven't been able to find any public methods to do this :(
Hopefully someone has an answer for what should be an easy question! :)
回答1:
If you are using Newtonsoft You can do this
var jsonString = JsonConvert.SerializeObject(yourObject);
using (StreamWriter writer =
new StreamWriter("SerializedObject.json"))
{
writer.Write(jsonString);
}
To read the JSON file you can do this
using (StreamReader reader =
new StreamReader("SerializedObject.json"))
{
string jsonString = reader.ReadToEnd();
YourObject ObjectFromJson = JsonConvert.DeserializeObject<YourObject>(jsonString);
}
回答2:
I think you can use ToString() method for parsing. You override the ToString() method in your Class and write parsing code on it.
For more information you can look into below link https://msdn.microsoft.com/en-us/library/system.object.tostring(v=vs.110).aspx
来源:https://stackoverflow.com/questions/39866578/how-to-save-parseobject-to-disk-in-net