C# Json.net反序列化错误(JSONReaderException)
主程序中的代码C# Json.net反序列化错误(JSONReaderException),c#,.net,json,json.net,json-deserialization,C#,.net,Json,Json.net,Json Deserialization,主程序中的代码 controller.modelToFile("passwords/test.json"); controller.deJSONizeModel("passwords/test.json"); 控制器的modelToFile: public void modelToFile(String filename) { System.IO.File.WriteAllText(filename, JSONizeModel()); } 控制器的JSONIE
controller.modelToFile("passwords/test.json");
controller.deJSONizeModel("passwords/test.json");
控制器的modelToFile:
public void modelToFile(String filename) {
System.IO.File.WriteAllText(filename, JSONizeModel());
}
控制器的JSONIEModel:
public String JSONizeModel() {
Newtonsoft.Json.JsonSerializerSettings jss = new Newtonsoft.Json.JsonSerializerSettings();
jss.Formatting = Newtonsoft.Json.Formatting.Indented;
Newtonsoft.Json.Serialization.DefaultContractResolver dcr = new Newtonsoft.Json.Serialization.DefaultContractResolver();
dcr.DefaultMembersSearchFlags |= System.Reflection.BindingFlags.NonPublic;
jss.ContractResolver = dcr;
return Newtonsoft.Json.JsonConvert.SerializeObject(model, jss);
}
控制器的deJSonizeModel:
public void deJSONizeModel(String json) {
model = JsonConvert.DeserializeObject<Model>(json);
}
密码类别:
public String description { get; set; }
public String password { get; set; }
public Password(String description, String password) {
this.description = description;
this.password = password;
}
请帮忙。例外情况是Newtonsoft.Json.JSONReaderException
程序日志:
A first chance exception of type 'Newtonsoft.Json.JsonReaderException' occurred in Newtonsoft.Json.dll
A first chance exception of type 'Newtonsoft.Json.JsonReaderException' occurred in Newtonsoft.Json.dll
An unhandled exception of type 'Newtonsoft.Json.JsonReaderException' occurred in Newtonsoft.Json.dll
Additional information: Error parsing boolean value. Path '', line 0, position 0.
解决了!
devsoniemodel
的参数是一个文件,但需要JSON 你能在帖子中添加更多关于这个例外的信息吗?InnerException如果有的话,可能是stacktrace。是的,这是你的答案,但你把它贴在了问题部分。我提取了它,并以你的名义发布在这里。
public String description { get; set; }
public String password { get; set; }
public Password(String description, String password) {
this.description = description;
this.password = password;
}
A first chance exception of type 'Newtonsoft.Json.JsonReaderException' occurred in Newtonsoft.Json.dll
A first chance exception of type 'Newtonsoft.Json.JsonReaderException' occurred in Newtonsoft.Json.dll
An unhandled exception of type 'Newtonsoft.Json.JsonReaderException' occurred in Newtonsoft.Json.dll
Additional information: Error parsing boolean value. Path '', line 0, position 0.