反序列化包含数组的JSON数组?

时间:2013-06-12 15:48:42

标签: c# json .net-3.5 linq-to-entities json.net

当我尝试使用.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" } ] ]

1 个答案:

答案 0 :(得分:4)

JsonConvert.DeserializeObject<List<List<People>>>应该有用。