2014-01-11 68 views
-1

我累了有关分析认为JSON响应:如何解析该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); 

,这使得应用程序崩溃.. 。

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

+0

请提供例外,你有 –

+2

我刚刚测试过你的代码,工作得很好。 – MarcinJuraszek

+0

您可能需要用'[JsonProperty(“​​”)''装饰您的模型。看看这里:http://stackoverflow.com/q/11126242/2638872 – mrtig

回答

1

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

+0

是的,你有权利!现在它工作正常!谢谢 – user3163231