Ci-dessous ma chaîne JSONComment deserialize donné chaîne JSON à une classe définie
Json Chaîne
{
"RestResponse": {
"messages": [
"Country found matching code [IN]."
],
"result": {
"name": "India",
"alpha2_code": "IN",
"alpha3_code": "IND"
}
}
}
J'ai fait ces classes dans Xamarin mais n'est pas l'analyse syntaxique Json à des objets, S'il vous plaît guider.
public class Country
{
[JsonProperty(PropertyName = "RestResponse")]
public List<myRestResponse> RestResponse { get; set; }
}
public class myRestResponse
{
[JsonProperty(PropertyName = "messages")]
public List<string> messages { get; set; }
[JsonProperty(PropertyName = "result")]
public List<Result> result { get; set; }
}
public class Result
{
[JsonProperty(PropertyName = "name")]
public string name { get; set; }
[JsonProperty(PropertyName = "alpha2_code")]
public string alpha2_code { get; set; }
[JsonProperty(PropertyName = "alpha3_code")]
public string alpha3_code { get; set; }
}
Je désérialisation en utilisant le code ci-dessous
var content = await response.Content.ReadAsStringAsync();
Country country = JsonConvert.DeserializeObject<Country>(content);
'RestResponse' n'est pas une collection pour commencer et n'est' result'. – juharr