首页 > 代码库 > JsonConvert序列化问题

JsonConvert序列化问题

返回的Json数据如下:

[[1400025600,9633460,9667535,2698.09,2734.73,2749,2698.08,25333.3057,11784.9,13548.4,69148900],[1400112000,9667536,9700700,2734.94,2771.01,2790,2731.48,24260.1011,11824.5,12435.6,67093300],[1400198400,9700701,9736706,2771,2789,2816.33,2730,34824.2351,17912.2,16912,96751200],[1400284800,9736707,9752556,2789,2782.03,2800,2775,9279.0273,4603.73,4675.29,25840300]]

 

使用:dynamic jsonRespot = JsonConvert.DeserializeObject<ExpandoObject>(resposeData); 进行解析时,报如下错误:

Cannot deserialize the current JSON array (e.g. [1,2,3]) into type ‘System.Dynamic.ExpandoObject‘ 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 ‘‘, line 1, position 1.

 

解决方法,用如下语句序列化:

JArray jsonObj = (JArray)JsonConvert.DeserializeObject(resposeData);

 

JsonConvert序列化问题