我试图解析一个JSON响应字符串到我的类对象..我无法弄清楚这一点,我需要一些帮助。反序列化与列表对象
我使用json.net参考,但我cant't找到我要找:(
的json:
{
"@companyName": "Company Name",
"@version": "1.0",
"@generatedDate": "3/1/10 2:10 PM",
"application": [
{
"@name": "Application #1 name",
"@apiKey": "1234",
"@createdDate": "2010-03-01",
"@platform": "Platform name"
},
{
"@name": "Application #1 name",
"@apiKey": "1234",
"@createdDate": "2010-03-01",
"@platform": "Platform name"
}
]
}
我对JSON根类是:
public class RootObject
{
[JsonProperty]
public string companyName { get; set; }
[JsonProperty]
public string version { get; set; }
[JsonProperty]
public string generatedDate { get; set; }
[JsonProperty]
public List<Application> application { get; set; }
}
我的子类(应用程序列表):
public class Application
{
[JsonProperty]
public string name { get; set; }
[JsonProperty]
public string apiKey { get; set; }
[JsonProperty]
public string createdDate { get; set; }
[JsonProperty]
public string platform { get; set; }
}
解析它,我有现在下面的代码:
JObject obj = JObject.Parse(e.Result);
applications = new RootObject
{
companyName = (string) obj["companyName"],
version = (string) obj["version"],
generatedDate = (string) obj["generatedDate"],
application = ???????? (how to make a list here?)
}
提前感谢!
“@”字符的好处L.B.当我在回答问题时,我甚至没有注意到他们。 :) – jdonley83
无法将JSON对象反序列化为类型'System.Collections.Generic.List'1 [应用程序] –
它可以在我的机器上正常工作,但您也可以尝试'public Application [] application {get;组; }' –