我想使用 RestSharp 和 Json.Net 制作一些客户端程序。我想反序列化和分类来自 Rest 服务 Api 的一些 JSON 响应。
我要求这样的服务
http://api.someservice.com/Term?parentId=123
服务的响应就像打击一样。
{
"statusCode":"OK",
"123":
[
{"name":"Foo","childId":"4567","parentId":"123"},
{"name":"Bar","childId":"8901","parentId":"123"},
]
]
它似乎被归类为打击。
public class 123
{
public string name { get; set; }
public string childId { get; set; }
public string parentId { get; set; }
}
public class RootObject
{
public string statusCode { get; set; }
public List<123> 123 { get; set; }
}
问题是每次请求(“123”)更改类和属性的名称。无论如何,我的目的是为每个 {"name....} 字符串创建一个实例。
我想知道使用 RestSharp 和 Json.Net 填充每个原始名称和 childId 的最佳方法。或者,有什么方法可以忽略 "123":[] 而只是得到我感兴趣的代码部分?
感谢您的时间。