我想從API服務反序列化對象數組。.NET C#JsonConvert.DeserializeObject數組
來自API的數據具有以下形式:
{
"id": "9286",
"nome": "Bairro Novo",
"num_lotes": "312",
"num_quadras": "9",
"plots_id": "159351",
"geo_data": [
{
"loteamentos_id": "9286",
"G": "-7.27087569384820000000",
"K": "-34.90980863571200000000",
"index": "0",
"code": "V"
},
{
"loteamentos_id": "9286",
"G": "-7.27234968660550000000",
"K": "-34.90971207618700000000",
"index": "1",
"code": "V"
},
{
"loteamentos_id": "9286",
"G": "-7.27317448188540000000",
"K": "-34.90458905696900000000",
"index": "2",
"code": "V"
},
{
"loteamentos_id": "9286",
"G": "-7.27176434710060000000",
"K": "-34.90472316741900000000",
"index": "3",
"code": "V"
},
{
"loteamentos_id": "9286",
"G": "-7.27202508786680000000",
"K": "-34.90719884634000000000",
"index": "15",
"code": "C"
}
]
},
類Loteamento:
public class Loteamento {
[JsonProperty("id")]
public string id { get; set; }
[JsonProperty("nome")]
public string nome { get; set; }
[JsonProperty("num_lotes")]
public string num_lotes { get; set; }
[JsonProperty("num_quadras")]
public string num_quadras { get; set; }
[JsonProperty("plots_id")]
public string plots_id { get; set; }
[JsonProperty("geo_data")]
public List<GeoData> geo_data { get; set; }
}
和類地理數據:
public class GeoData {
[JsonProperty("loteamentos_id")]
public string loteamentos_id { get; set; }
[JsonProperty("G")]
public string G { get; set; }
[JsonProperty("K")]
public string K { get; set; }
[JsonProperty("index")]
public string index { get; set; }
[JsonProperty("code")]
public string code { get; set; }
}
的問題是,我得到一個錯誤,不知道如何獲得一個數組。
在我的代碼有:
List<Loteamento>[] loteamentos = null;
loteamentos = JsonConvert.DeserializeObject<List<Loteamento>>(dataObj.Result);
有什麼不對?
「我得到一個錯誤」 ...... *什麼錯誤*? –
另外,爲什麼你想分配一個列表到一個列表數組? –
@PatrickHofman Upsss!你是對的。這是問題!謝謝。 – Apalabrados