我有以下JSON,我試圖反序列化。DeSerializing JSON返回空C#
{
"output-parameters":[
{
"value":{
"array":{
"elements":[
{
"string":{
"value":"cp-100"
}
},
{
"string":{
"value":"cp-101"
}
},
{
"string":{
"value":"cp-100"
}
},
{
"string":{
"value":"cp-101"
}
},
{
"string":{
"value":"cp-100"
}
}
]
}
},
"type":"Array/string",
"name":"Tags",
"scope":"local"
},
{
"value":{
"string":{
"value":"subscribed"
}
},
"type":"string",
"name":"Error",
"scope":"local"
}
]
}
我創建了以下類的JSON
public class OutputParameter
{
[JsonProperty(PropertyName = "value")]
public value value { get; set; }
[JsonProperty(PropertyName = "name")]
public string name { get; set; }
}
public class value
{
[JsonProperty(PropertyName = "array")]
public array_ array_ { get; set; }
}
public class array_
{
[JsonProperty(PropertyName = "elements")]
public element[] element { get; set; }
}
public class element
{
[JsonProperty(PropertyName = "value")]
public string value { get; set; }
}
而我反序列化它,我沒有得到任何錯誤綁定。我也可以輕鬆導航。
但是當我試圖獲取元素[n](output_parameters [0] .value.array_.element [0] .value)的值時。它返回null。
這裏有什麼問題?
注:我只需要從JSON中取少數值。例如,我不需要像 「type」:「string」, 「name」:「Error」, 「scope」:「local」 這就是爲什麼我創建這樣的C#類的原因。
你不應該尋找 「output_parameters [0] .value.array_.element [0] .string.value」? –
嘗試使用http://json2csharp.com/從JSON生成C#類? –