【发布时间】:2017-10-19 12:05:12
【问题描述】:
下面是我的 Json 字符串
Json 字符串
{
"RestResponse": {
"messages": [
"Country found matching code [IN]."
],
"result": {
"name": "India",
"alpha2_code": "IN",
"alpha3_code": "IND"
}
}
}
我在 Xamarin 中创建了这些类,但没有将 Json 解析为对象,请指导。
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; }
}
我正在使用下面的代码进行反序列化
var content = await response.Content.ReadAsStringAsync();
Country country = JsonConvert.DeserializeObject<Country>(content);
【问题讨论】:
-
RestResponse不是初学者的集合,result也不是。