我是 JSon 的新手,尤其是 JSon.Net。我正在尝试在 Windows Phone 上使用 LiveSDK,但在解析 JSon 响应时遇到问题。我正在尝试读取日历信息,但无法解析。下面是我下载 Json 的代码和我的类定义。我在定义“用户”的行出现异常。
void getCal_DownloadCompleted(object sender, LiveDownloadCompletedEventArgs e)
{
if (e.Error == null)
{
using (var reader = new StreamReader(e.Result))
{
var json = reader.ReadToEnd();
var user = JsonConvert.DeserializeObject<Calendar>(json);
}
}
}
我的日历课
[JsonObject(MemberSerialization.OptIn)]
public class Calendar
{
[JsonProperty(PropertyName="name")]
public string Name{get; set;}
[JsonProperty(PropertyName = "id")]
public string Id{get; set;}
[JsonProperty(PropertyName = "description")]
public string Description{get; set;}
[JsonProperty(PropertyName = "created_time")]
public string CreatedTime{get; set;}
[JsonProperty(PropertyName = "updated_time")]
public string UpdatedTime{get; set;}
[JsonProperty(PropertyName = "from")]
public object From{get; set;}
[JsonProperty(PropertyName = "is_default")]
public bool IsDefault{get; set;}
[JsonProperty(PropertyName = "subscription_location")]
public string SubscriptionLocation{get; set;}
[JsonProperty(PropertyName = "permissions")]
public string Permissions{get; set;}
}
收到的 JSON 格式
{
"data": [
{
"id": "calendar.42d4dbc866f94c83849c88c6eb9985bc",
"name": "Birthday calendar",
"description": "If you have birthdays listed for your contacts, they'll appear on this calendar. You can add more birthdays, but you can't add other types of events.",
"created_time": "2011-08-05T19:41:04+0000",
"updated_time": "2011-08-05T19:41:04+0000",
"from": {
"name": null,
"id": null
},
"is_default": false,
"subscription_location": null,
"permissions": "read"
},{
...
}
] }
我在使用 LiveSDK GetAsync() 时运气不佳,所以我改用了 DownloadAsync()。这种方法更好吗?
谢谢