當我嘗試反序列化與.NET JavaScriptDeserializer下面,我得到錯誤信息:Type 'People' is not supported for deserialization of an array
反序列化包含數組的JSON數組?
當我使用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" } ] ]
美麗。有效。謝謝Tia。 – Xaisoft