小编Ste*_*ven的帖子

如何使用Newtonsoft.Json反序列化JSON数组

[
   {
      "receiver_tax_id":"1002",
      "total":"6949,15",
      "receiver_company_name":"Das Company",
      "receiver_email":"info@another.com",
      "status":0
   },
   {
      "receiver_tax_id":"1001",
      "total":"39222,49",
      "receiver_company_name":"SAD company",
      "receiver_email":"info@mail.com",
      "status":1
   }
]
Run Code Online (Sandbox Code Playgroud)

嗨,这是我的Json数据,但我不能反序列化它.我想只检查"状态"值.(第一个对象"status"0,第二个对象"status"1).

示例定义:

public class Example 
{
    [JsonProperty("receiver_tax_id")] 
    public string receiver_tax_id { get; set; }
    [JsonProperty("total")] 
    public string total { get; set; }
    [JsonProperty("receiver_company_name")] 
    public string receiver_company_name { get; set; }
    [JsonProperty("receiver_email")] 
    public string receiver_email { get; set; }
    [JsonProperty("status")] 
    public int status { get; set; } 
}
Run Code Online (Sandbox Code Playgroud)

反序列化代码:

var des = (Example)JsonConvert.DeserializeObject(responseString, typeof(Example)); 
Console.WriteLine(des.status[0].ToString());
Run Code Online (Sandbox Code Playgroud)

c# json deserialization

21
推荐指数
2
解决办法
4万
查看次数

标签 统计

c# ×1

deserialization ×1

json ×1