gpt4 book ai didi

c# - 无法将对象数组从 JSON 反序列化为 C# 对象

转载 作者:行者123 更新时间:2023-11-30 18:07:57 25 4
gpt4 key购买 nike

我在让 JavascriptSerializer 反序列化对象数组时遇到问题。我不太确定我错过了什么。

这是我的对象...

public class HomefinderResult
{
public Data data;
public List<Listing> listings;
public Status status;


public class Listing
{
public string recordingDate;
public Buyer buyer;
public double distance;
public string id;

public class Buyer
{
public Address address;
public string phone;
public string firstName;
public string lastName;

public class Address
{
public string line1;
public string city;
public string state;
public string zip;
public string county;
public string latitude;
public string longitude;

}
}
}

public class Data
{
public Meta meta;
public class Meta
{
public int totalMatched;
public int totalPages;
public int currentPage;
public double executionTime;
}
}

public class Status
{
public int code;
public string[] errorStack;
}
}

这是我要反序列化的 json 响应...

     {
"data":{
"meta":{
"totalMatched":126,
"totalPages":7,
"currentPage":1,
"executionTime":0.26153302192688
},
"listings":[
{
"recordingDate":"2010-06-07",
"buyer":{
"address":{
"line1":"999 Meadow Rd",
"city":"Oak Ridge",
"state":"TN",
"zip":"99999",
"county":"Anderson",
"latitude":"99.0316920000",
"longitude":"-99.2476320000"
},
"phone":"9995551234",
"firstName":"xxx",
"lastName":"xxx"
},
"distance":18.088793566409,
"purchasePrice":"975000",
"id":"70a706d46c5e1db7417b78c159467431"
},

{
"recordingDate":"2010-06-04",
"buyer":{
"address":{
"line1":"999 Willow Ln",
"city":"Oak Ridge",
"state":"TN",
"zip":"99999",
"county":"Anderson",
"latitude":"99.0045700000",
"longitude":"-99.3182850000"
},
"firstName":"xxx",
"lastName":"xxx",
"gender":"Female"
},
"distance":22.244494041996,
"purchasePrice":"201000",
"id":"dda41ec8150c8648a7e9926b2c5fd468"
}
]
},
"status":{
"code":200,
"errorStack":null
}
}

我做错了什么?

最佳答案

切换到 JSON.NET 并遇到同样的问题后,我走了几分钟又回来了。我发现了我的问题——我需要将列表嵌套在数据中,而不是在同一层。

关于c# - 无法将对象数组从 JSON 反序列化为 C# 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3630242/

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