我使用 Newtonsoft.json 反序列化这个 json
{
"pdf_info": [
[
-> this is a object {
"order_serial_no": "xxxxx",
// more properties
},
-> this is an array ["xxxx", "x"]
]
]
}
在java中,我可以使用以下代码来实现这一点。
JSONArray pdfArray = JSONArray.parseArray(pdf_info);
String pdfArrayOne = pdfArray.getString(0);
JSONArray jsonArray = JSONObject.parseObject(pdfArrayOne, JSONArray.class);
String jsonData = jsonArray.getString(0);
Pdf pdf = JSONObject.parseObject(jsonData, Pdf.class);
那么,如何使用 newtonsoft.json 反序列化这个 json
显然(删除您的评论后)这将是您的对象的 c# 类(将 json 复制到剪贴板-> 在 Visual Studio 中“编辑-> 特殊粘贴-> 将 json 粘贴为类”-查看更多信息)
public class Rootobject
{
public object[][] pdf_info { get; set; }
}
定义此类型,您将能够使用以下方法反序列化它:
Newtonsoft.Json.JsonConvert.DeserializeObject<Rootobject>(System.IO.File.ReadAllText(fileName));
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句