2015-04-02 41 views
0

我从zoho获得json。我有这样一个JSON如下:Json反序列化没有结果

{ 
    "response": { 
    "result": { 
     "Leads": { 
     "row": [ 
      { 
      "no": "1", 
      "FL": [ 
       { 
       "content": "1325469000000679001", 
       "val": "LEADID" 
       }, 
       { 
       "content": "1325469000000075001", 
       "val": "SMOWNERID" 
       }, 
       { 
       "content": "Geoff", 
       "val": "Lead Owner" 
       }, 
      ] 
      }, 
      { 
      "no": "2", 
      "FL": [ 
       { 
       "content": "1325469000000659017", 
       "val": "LEADID" 
       }, 
       { 
       "content": "1325469000000075001", 
       "val": "SMOWNERID" 
       }, 
       { 
       "content": "Geoff", 
       "val": "Lead Owner" 
       }, 
      ] 
      }, 

     ] 
     } 
    }, 
    "uri": "/crm/private/json/Leads/getRecords" 
    } 
} 

我使用以下类:

public class Row 
{ 

    [JsonProperty(PropertyName = "row")] 
    public List<Leads> row { get; set; } 

} 

public class Leads 
{ 
    [JsonProperty(PropertyName = "no")] 
    public string nbr { get; set; } 

    [JsonProperty(PropertyName = "FL")] 
    public List<Lead> FieldValues { get; set; } 

} 

public class Lead 
{ 

    [JsonProperty(PropertyName = "content")] 
    public string Content { get; set; } 

    [JsonProperty(PropertyName = "val")] 
    public string Val { get; set; } 

} 

我尝试反序列化JSON,并取回什么:

var mList = JsonConvert.DeserializeObject<IDictionary<string, Row>>(result); 

这是第一次与Json合作,所以任何帮助将不胜感激!

+0

http://www.newtonsoft.com/json/help/html/SerializationAttributes.htm – 2015-04-02 20:26:15

+0

使用剪贴板上的JSON字符串,您可以执行**编辑 - >选择性粘贴 - >粘贴JSON作为类**和VS会为你创建JSON的类 – Plutonix 2015-04-02 20:42:56

回答

3

通常发生这种情况是因为您的反序列化类模型是错误的。而不是试图手工制作我喜欢使用的课程http://json2csharp.com。只需插入您的JSON,它就会为您提供必要的C#类。在你的情况下,它提供了以下内容。

public class FL 
{ 
    public string content { get; set; } 
    public string val { get; set; } 
} 

public class Row 
{ 
    public string no { get; set; } 
    public List<FL> FL { get; set; } 
} 

public class Leads 
{ 
    public List<Row> row { get; set; } 
} 

public class Result 
{ 
    public Leads Leads { get; set; } 
} 

public class Response 
{ 
    public Result result { get; set; } 
    public string uri { get; set; } 
} 

public class RootObject 
{ 
    public Response response { get; set; } 
} 

然后,您可以反序列化为RootObject使用:

var mList = JsonConvert.DeserializeObject<RootObject>(result); 

随意命名RootObject以任何名义,你更喜欢。

+0

这很棒!谢谢! – 2015-04-02 20:05:58