我試圖解析一個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;組; }' –