问题描述
我需要将ParseObjects列表保存到C#磁盘中,并且想知道是否有人对如何实现此目标有任何建议.
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.
我确信Parse .NET SDK可以将ParseObjects转换为JSON,因为这是在转换为解析服务器的过程中使用的格式,但是我找不到任何公共方法来做到这一点: (
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! :)
推荐答案
如果您使用的是 Newtonsoft 可以做到
If you are using Newtonsoft You can do this
var jsonString = JsonConvert.SerializeObject(yourObject);
using (StreamWriter writer =
new StreamWriter("SerializedObject.json"))
{
writer.Write(jsonString);
}
要读取JSON文件,您可以执行此操作
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);
}
这篇关于如何将ParseObject保存到.NET中的磁盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!