C# 使用JSon.Net反序列化LiveSDK日历
我不熟悉JSon,尤其是JSon.Net。我试图在Windows Phone上使用LiveSDK,但在解析JSon响应时遇到问题。我试图读取日历信息,但无法对其进行解析。下面是我下载Json和类定义的代码。我在定义“用户”的行中遇到一个异常C# 使用JSon.Net反序列化LiveSDK日历,c#,json.net,C#,Json.net,我不熟悉JSon,尤其是JSon.Net。我试图在Windows Phone上使用LiveSDK,但在解析JSon响应时遇到问题。我试图读取日历信息,但无法对其进行解析。下面是我下载Json和类定义的代码。我在定义“用户”的行中遇到一个异常 void getCal_DownloadCompleted(object sender, LiveDownloadCompletedEventArgs e) { if (e.Error == null) {
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);
}
}
}
接收到的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()。这种方法更好吗
谢谢您的序列化类似乎与JSON不匹配。JSON返回一个名为
data
的属性的对象,该属性是一个数组,包含您定义的Calendar
类的元素
尝试添加一个新类,如:
[JsonObject(MemberSerialization.OptIn)]
public class AppointmentList
{
[JsonProperty(PropertyName="data")]
public List<Calendar> data {get; set;}
}
[JsonObject(MemberSerialization.OptIn)]
公开班级任命名单
{
[JsonProperty(PropertyName=“data”)]
公共列表数据{get;set;}
}
并反序列化如下:
var user = JsonConvert.DeserializeObject<AppointmentList>(json);
var user=JsonConvert.DeserializeObject(json);
嘿,非常感谢。我发誓我已经试过了,但没用,但现在一切都好了。
var user = JsonConvert.DeserializeObject<AppointmentList>(json);