反序列化一个包含数组的JSON数组

本文关键字:数组 包含 JSON 一个 反序列化 | 更新日期: 2023-09-27 18:18:17

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

当我使用JSON.NETJsonConvert.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.

我使用的是link - to - entities,所以我认为我不能给它添加任何属性。

args["xldata"]是一个以"xldata"为键,以下面的JSON字符串为值的Dictionary

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

反序列化一个包含数组的JSON数组

JsonConvert.DeserializeObject<List<List<People>>>