うまくいけば助けてください。私は要素の1つの "ラベル"を印刷したいと思います。c# - 大括弧で区切られたJSONはRestSharpでデシリアライズできません
JSON入力:JsonDeserializer
public string callGACWithPLZSandbox(string plz)
{
var client = new RestClient("http://rest.sandbox-immobilienscout24.de");
var request = new RestRequest("restapi/api/gis/v2.0/geoautocomplete/DEU", Method.GET);
client.ClearHandlers();
client.AddHandler("application/json", new JsonDeserializer());
request.AddQueryParameter("i", plz);
request.AddQueryParameter("t", "postcode");
request.AddHeader("bla", "blub");
IRestResponse<Rootobject> response = client.Execute<Rootobject>(request);
return response.Data.Property1[1].entity.label;
}
そして、クラス
class Rootobject
{
public Class1[] Property1 { get; set; }
}
class Class1
{
public Entity entity { get; set; }
public Match[] matches { get; set; }
}
class Entity
{
public string type { get; set; }
public string id { get; set; }
public string label { get; set; }
public string value { get; set; }
}
class Match
{
public int offset { get; set; }
public int length { get; set; }
}
と
[
{
"entity":{
"type":"postcode",
"id":"P11516",
"label":"18314 Divitz-Spoldershagen",
"value":"18314"
},
"matches":[
{
"offset":0,
"length":5
}
]
},
{
"entity":{
"type":"postcode",
"id":"P11541",
"label":"18314 Kenz-Küstrow",
"value":"18314"
},
"matches":[
{
"offset":0,
"length":5
}
]
},
{
"entity":{
"type":"postcode",
"id":"P11549",
"label":"18314 Löbnitz",
"value":"18314"
},
"matches":[
{
"offset":0,
"length":5
}
]
},
{
"entity":{
"type":"postcode",
"id":"P11551",
"label":"18314 Lüdershagen",
"value":"18314"
},
"matches":[
{
"offset":0,
"length":5
}
]
}
]
とAPI呼び出し私が間違って何をしているのですか?いずれかの次の2つのオプションを持っている...
JSONは配列を表しますが、単一のオブジェクトに逆シリアル化しています。代わりに 'List'リストにデシリアライズしてください。 –
ありがとうございますが、 'return response.Data [0] .entity.label;'は依然としてNullReferenceExceptionをスローします。他のアイデア? – fmielke