我在尝试将JSON反序列化到数据集中时收到以下错误。可能是什么问题?感谢您的帮助。
错误:Newtonsoft。Json。JsonSerializationException:读取DataTable时出现意外的JSON令牌。应为StartArray,实际为StartObject。路径"status",第1行,位置11。
Dim ds As DataSet = JsonConvert.DeserializeObject(Of DataSet)(strJSON)
以下是JSON的示例:
{
"status": {
"version": "1.0.0",
"code": 0,
"msg": "SuccessWithResult",
"total": 10000,
"page": 1,
"pagesize": 10
},
"property": [
{
"identifier": {
"obPropId": 15096656312086,
"fips": "12086",
"apn": "0232340220100",
"apnOrig": "232340220100",
"attomId": 150966563
},
"lot": {
"lotSize1": 0.249
},
"address": {
"country": "US",
"countrySubd": "FL",
"line1": "2014 ALTON RD",
"line2": "MIAMI BEACH, FL 33140",
"locality": "Miami Beach",
"matchCode": "ExaStr",
"oneLine": "2014 ALTON RD, MIAMI BEACH, FL 33140",
"postal1": "33140",
"postal2": "4532",
"postal3": "C007"
},
"location": {
"accuracy": "Street",
"elevation": 0.0,
"latitude": "25.796309",
"longitude": "-80.140216",
"distance": 0.0,
"geoid": "CO12086, CS1292171, DB1200390, MT30002544, ND0000461513, ND0004455664, PL1245025, RS0000471909, ZI33140"
},
"summary": {
"propclass": "Single Family Residence / Townhouse",
"propsubtype": "MISCELLANEOUS INDUSTRIAL",
"proptype": "SFR",
"yearbuilt": 1927,
"propLandUse": "SFR",
"propIndicator": "10"
},
"building": {
"size": {
"universalsize": 4358
},
"rooms": {
"bathstotal": 5.0,
"beds": 6
}
},
"vintage": {
"lastModified": "2020-3-13",
"pubDate": "2020-3-14"
}
},
{
"identifier": {
"obPropId": 862064312086,
"fips": "12086",
"apn": "0232340220080",
"apnOrig": "232340220080",
"attomId": 8620643
},
"lot": {
"lotSize1": 0.2063
},
"address": {
"country": "US",
"countrySubd": "FL",
"line1": "2008 ALTON RD",
"line2": "MIAMI BEACH, FL 33140",
"locality": "Miami Beach",
"matchCode": "ExaStr",
"oneLine": "2008 ALTON RD, MIAMI BEACH, FL 33140",
"postal1": "33140",
"postal2": "4532",
"postal3": "C007"
},
"location": {
"accuracy": "Street",
"elevation": 0.0,
"latitude": "25.796222",
"longitude": "-80.140290",
"distance": 0.0,
"geoid": "CO12086, CS1292171, DB1200390, MT30002544, ND0000461513, ND0004455664, PL1245025, RS0000471909, ZI33140"
},
"summary": {
"propclass": "Single Family Residence / Townhouse",
"propsubtype": "MISCELLANEOUS INDUSTRIAL",
"proptype": "SFR",
"yearbuilt": 1920,
"propLandUse": "SFR",
"propIndicator": "10"
},
"building": {
"size": {
"universalsize": 3037
},
"rooms": {
"bathstotal": 3.0,
"beds": 4
}
},
"vintage": {
"lastModified": "2020-3-13",
"pubDate": "2020-3-14"
}
}
]
}
当您在结果的开始和结束处获得响应连接数组符号时,只需要做一件简单的事情
dynamic result = await response.Content.ReadAsStringAsync();
dt = (DataTable)JsonConvert.DeserializeObject("["+result+"]", typeof(DataTable));