我有一个 JSON 字符串,我需要一些帮助来反序列化它。
没有什么对我有用...这是 JSON:
{
"response": [{
"loopa": "81ED1A646S894309CA1746FD6B57E5BB46EC18D1FAff",
"drupa": "D4492C3CCE7D6F839B2BASD2F08577F89A27B4ff",
"images": [{
"report": {
"nemo": "unknown"
},
"status": "rock",
"id": "7e6ffe36e-8789e-4c235-87044-56378f08m30df",
"market": 1
},
{
"report": {
"nemo": "unknown"
},
"status": "rock",
"id": "e50e99df3-59563-45673-afj79e-e3f47504sb55e2",
"market": 1
}
]
}]
}
我有一个类的示例,但我不必使用这些类。我不介意使用其他类。
这些是类:
public class Report
{
public string nemo { get; set; }
}
public class Image
{
public Report report { get; set; }
public string status { get; set; }
public string id { get; set; }
public int market { get; set; }
}
public class Response
{
public string loopa { get; set; }
public string drupa{ get; set; }
public Image[] images { get; set; }
}
public class RootObject
{
public Response[] response { get; set; }
}
我想提一下,我已经有了 Newtonsoft.Json,所以我可以使用那里的一些功能。
我该怎么做?
最佳答案
我在我的代码中使用这样的,它工作正常
下面是你需要编写的一段代码
using System.Web.Script.Serialization;
JavaScriptSerializer oJS = new JavaScriptSerializer();
RootObject oRootObject = new RootObject();
oRootObject = oJS.Deserialize<RootObject>(Your JSon String);
关于c# - 如何在 C# .NET 中反序列化复杂的 JSON 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16339167/