如何解析json响应?

时间:2014-01-11 22:45:20

标签: c# json windows-phone-7 restsharp

我厌倦了解析json的回应:

我为模特准备了一些课程:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Announcements
{
    public class Private
    {
        public string created_at { get; set; }
        public int id { get; set; }
        public string text { get; set; }
        public string title { get; set; }
        public string updated_at { get; set; }
        public int user_id { get; set; }
    }

    public class User
    {
        public string first_name { get; set; }
        public int id { get; set; }
        public string last_name { get; set; }
    }

    public class Public
    {
        public string created_at { get; set; }
        public int id { get; set; }
        public string text { get; set; }
        public string title { get; set; }
        public User user { get; set; }
    }

    public class RootObject
    {
        public List<Private> @private { get; set; }
        public List<Public> @public { get; set; }
    }
}

现在是时候反序列化了反应:

            var tempUsersArray = JsonConvert.DeserializeObject<Announcements.RootObject>(response.Content);

这会让应用程序崩溃......

任何人都知道我做错了什么?

1 个答案:

答案 0 :(得分:1)

您没有为课程定义权限,请将class Announcements改为public class Announcements。现在它应该正常工作,请测试这个技巧。