2 回答

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊
在這個(gè)問題中,您可能會將您的 json 解析為您的類列表,就像List<ClassName>
您應(yīng)該排除 List<> 一樣,因?yàn)槟趥魅氲?json 中有單個(gè)主要對象

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個(gè)贊
如果您的數(shù)組中的項(xiàng)目report不固定意味著這些項(xiàng)目的計(jì)數(shù)從 1 到 N,那么為每個(gè)項(xiàng)目聲明屬性很困難,并且您的類對象結(jié)構(gòu)變得乏味。
因此,您需要收集所有物品,Dictionary以便它可以解析您的物品從 1 到 N。
這些類對象適合您的 json。
class RootObj
{
public string somethingone { get; set; }
public string somethingtwo { get; set; }
public Information information { get; set; }
}
class Information
{
public Dictionary<string, string>[] report { get; set; }
}
你可以反序列化
RootObj mainObj = JsonConvert.DeserializeObject<RootObj>(json);
Console.WriteLine("somethingone: " + mainObj.somethingone);
Console.WriteLine("somethingtwo: " + mainObj.somethingtwo);
foreach (Dictionary<string, string> report in mainObj.information.report)
{
foreach (KeyValuePair<string, string> item in report)
{
string key = item.Key;
string value = item.Value;
Console.WriteLine(key + ": " + value);
}
}
Console.ReadLine();
輸出:
- 2 回答
- 0 關(guān)注
- 151 瀏覽
添加回答
舉報(bào)