gpt4 book ai didi

c# - 当前 JsonReader 项不是对象

转载 作者:太空狗 更新时间:2023-10-29 20:07:01 27 4
gpt4 key购买 nike

首先我制作了一个应用程序,然后我开始对其进行测试(知道这不是好方法),解析等一切正常,但在我进行了几次测试后出现了错误:

Newtonsoft.Json.JsonReaderException : Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.

错误发生在 jObject = JObject.Parse(content);arrayList = JArray.Parse(content);

internal JObject DoParse(string content)
{
JObject jObject = new JObject();
if (content != null)
{
if (content.Contains("Unable"))
{
MessageBox.Show("Not found.", "Error");
}
else
{
jObject = JObject.Parse(content);
}
}
return jObject;
}

internal JArray DoParseOnList(string content)
{
JArray arrayList = new JArray();
if (content != null)
{
if (content.Contains("Unable"))
{
MessageBox.Show("Not found.", "Error");
}
else
{

arrayList = JArray.Parse(content);
}
}
else { }
return arrayList;
}

有什么问题吗?顺便提一句。 string content 是我从服务器得到的json。提前致谢!

JSON

Test Name:  SetGroup
Test Outcome: Failed
Result Message: SetUp : Newtonsoft.Json.JsonReaderException : Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.
Result StandardOutput: [{"id":6208,"name":"test"},{"id":6315,"name":"jPOD v144 Testing"},{"id":6306,"name":"iButton Issue"},{"id":6424,"name":"Hybrid"}]
[{"id":6208,"name":"test"},{"id":6315,"name":"jPOD v144 Testing"},{"id":6306,"name":"iButton Issue"},{"id":6424,"name":"Hybrid"}]
[{"enabled":true,"scriptVersion":199,"configVersion":3,"name":"LMU3030 Hybrid Car Test based on 64.112 add ignition on-off"},{"enabled":true,"scriptVersion":199,"configVersion":2,"name":"LMU3030 Hybrid Car Test based on 50.106"},{"enabled":true,"scriptVersion":199,"configVersion":1,"name":"Hybrid car LMU 3030 Ignition test","description":""},{"enabled":true,"scriptVersion":64,"configVersion":113,"name":"based on 64.112 Engineering Build from calamp"},{"enabled":true,"scriptVersion":61,"configVersion":106},{"enabled":true,"scriptVersion":38,"configVersion":117},{"enabled":true,"scriptVersion":184,"configVersion":0},{"enabled":true,"scriptVersion":13,"configVersion":54},{"enabled":true,"scriptVersion":23,"configVersion":105,"name":"PULS Redirect to PROD","description":"Changes just Param 2320 to maint.vehicle-location.com"}]
[]
[{"message":"Not Implemented","vbusDeviceFiles":[],"vbusFileHistories":[]}]

最佳答案

我有类似的问题。
返回的 JSON 是 Array/List 而不是 Object。
相反,我使用 JArray.Parse 并且它有效。

jArray = JArray.Parse(content);

关于c# - 当前 JsonReader 项不是对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40790217/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com