gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 04:37:50 24 4
gpt4 key购买 nike

[
{
"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
}
]

嗨,这是我的 Json 数据,但我无法反序列化它。我只想检查“状态”值。 (第一个对象“状态”0,第二个对象“状态”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; }
}

反序列化代码:

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

最佳答案

试试这个代码:

public class Receiver 
{
public string receiver_tax_id { get; set;}
public string total { get; set;}
public string receiver_company_name { get; set;}
public int status { get; set;}
}

反序列化如下:

var result = JsonConvert.DeserializeObject<List<Receiver>>(responseString);
var status = result[0].status;

关于c# - 如何使用 Newtonsoft.Json 反序列化 JSON 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34103498/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com