最佳答案
目前,我有一些问题。我使用 C # 与 Json.NET。问题是,我总是得到:
{“解析值时遇到意外字符: e. 路径”,第0行,位置0。”}
我使用 Json.NET 的方式如下。我有一个类,应该保存。课程是这样的:
public class stats
{
public string time { get; set; }
public string value { get; set; }
}
public class ViewerStatsFormat
{
public List<stats> viewerstats { get; set; }
public String version { get; set; }
public ViewerStatsFormat(bool chk)
{
this.viewerstats = new List<stats>();
}
}
这个类的一个对象将被填充并保存为:
File.WriteAllText(tmpfile, JsonConvert.SerializeObject(current), Encoding.UTF8);
保存部分工作正常,文件存在并已填充。之后,该文件将被读回到类中,具体方法如下:
try
{
ViewerStatsFormat current = JsonConvert.DeserializeObject<ViewerStatsFormat>(tmpfile);
//otherstuff
}
catch(Exception ex)
{
//error loging stuff
}
现在在 current = line 上出现了一个例外:
{“解析值时遇到意外字符: e. 路径”,第0行,位置0。”}
我不知道为什么会这样。 JSON 文件如下-> 单击我,我是 JSON 链接
有人知道吗?