“从JsonReader读取JArray时出错。当前JsonReader项不是数组”

时间:2013-08-21 17:31:25

标签: c# json

我正在尝试用c#解析json net。我正在使用json .net

但它显示以下异常

Error reading JArray from JsonReader. Current JsonReader item is not an array: StartObject. Path '', line 1, position 1.

我用jquery创建json字符串。字符串的例子如下。

 {"0":{"tyreId":"","tyreNum":"dsf","tyreSecondHand":"false","tyreReplace":"true"},"1":{"tyreId":"","tyreNum":"gfd","tyreSecondHand":"true","tyreReplace":"true"}}

1 个答案:

答案 0 :(得分:11)

JSON文档表示一个对象(JObject),其中包含键"0""1"。它不是一个真正的数组,而是一个有点模仿数组的对象。

将文档作为对象读取,或将文档修复为真实数组:

[{"tyreId":"","tyreNum":"dsf","tyreSecondHand":"false","tyreReplace":"true"},{"tyreId":"","tyreNum":"gfd","tyreSecondHand":"true","tyreReplace":"true"}]