How to save ParseObject to disk in .NET

拥有回忆 提交于 2020-01-15 09:27:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!