Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用JSon.Net反序列化LiveSDK日历_C#_Json.net - Fatal编程技术网

C# 使用JSon.Net反序列化LiveSDK日历

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) {

我不熟悉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);
            }
        }
    }
接收到的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);