gpt4 book ai didi

c# - 反序列化包含数组的 JSON 数组?

转载 作者:太空宇宙 更新时间:2023-11-03 21:45:48 28 4
gpt4 key购买 nike

当我尝试使用 .NET JavaScriptDeserializer 反序列化以下内容时,我收到错误消息:Type 'People' is not supported for deserialization of an array

当我使用 JSON.NET 时喜欢JsonConvert.DeserializeObject<List<People>>(args["xldata"]); ,我得到了更详细的错误信息:

Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'People' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
Path '[0]', line 1, position 2.

我正在使用 Linq-To-Entities,所以我认为我不能向它添加任何属性。

args["xldata"]Dictionary以“xldata”为键,JSON下面的字符串作为值。

[
[
{
"CarrierHeaderId": 17,
"DetailHeaderId": 54,
"tds_client": "0000000996",
"carr_no": "0000019",
"name": "John Doe ",
"entry_type": "F",
"carrier_type": "2",
"scac_code": "1A ",
"cert_no": "2d ",
"address": "123 orange boulevard ",
"city": "Orlando ",
"state": "St",
"zip": "33333 ",
"phone": "9993023938",
"epa_num": "123 ",
"fein": "AA ",
"host_carr_no": "BB ",
"host_route_cd": "1a3 ",
"country": "US",
"CarrierHeaderLastUpdate": "6/11/2013 11:07 AM",
"term_id": "TDSTES8",
"trailer_req": "0",
"truck_req": "0",
"access_from": "1159",
"access_to": "2359",
"access_days": "YNNYYYN",
"ins_exp_date": "12/20/13",
"locked": "",
"lockout_date": "",
"lockout_reason": "",
"st_license": "",
"st_permit": "",
"icc_permit": "",
"liab_amt": "",
"haz_mat_excl": "",
"veh_liab_exp": "",
"veh_liab_amt": "",
"excess_liab_exp": "",
"excess_liab_amt": "",
"work_comp_exp": "",
"work_comp_amt": "",
"host_locked": "",
"host_lockout_date": "",
"host_lockout_reason": "",
"po_relno_req": null,
"general_exp": "",
"general_amt": "",
"access_profile": "",
"max_load_amt": "",
"own_consumption": "",
"full_redirect": "",
"det_required": "",
"seal_processing": "",
"email_group": "",
"email_address": "",
"shipment_origin": "",
"auto_confirm": "",
"bulk_transaction_picklist": "",
"ExciseNo": "",
"ERP_Carrier": "",
"CarrierDetailLastUpdate": "6/11/2013 5:03 PM"
}
]
]

最佳答案

JsonConvert.DeserializeObject<List<List<People>>>应该可以。

关于c# - 反序列化包含数组的 JSON 数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17069869/

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