【发布时间】:2012-01-17 15:06:30
【问题描述】:
我正在尝试将 JSON 响应字符串解析为我的类对象。我无法弄清楚这一点,我需要一些帮助。
我使用 json.net 参考,但找不到我要找的东西:(
我的 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?)
}
提前致谢!
【问题讨论】:
标签: c# json list windows-phone-7 json.net