First I made an application and then I've started doing test for it ( Know it is not good way ), everything works fine with parsing etc, but after i made few test got an error :
Newtonsoft.Json.JsonReaderException : Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.
Error occurs there jObject = JObject.Parse(content);
and there 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;
}
Any ideas what is wrong ?
Btw. string content
is json which i got from the server.
Thanks in advance !
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":[]}]
I have similar issue.
The returned JSON is Array/List but not Object.
Instead, I use JArray.Parse and it works.
jArray = JArray.Parse(content);
I ran into a very similar problem. The reason my JObject.Parse(json) would not work for me was because my Json had a beginning "[" and an ending "]". In order to make it work, I had to remove those two characters. I would inspect your Json and make sure that it starts with a { and ends with a }.
For me, I removed the first and last characters.
jsonResult = jsonResult.TrimStart(new char[] { '[' }).TrimEnd(new char[] { ']' });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With