3

I have following json

["a", ["amazon", "amazon.in", "aaj tak", "axis bank", "amar ujala", "amazon.com", "aadhar card", "airtel online recharge", "airtel", "axis bank internet banking", "amazon india", "air india"]]

Now I want to get it in list string

I tried

var obj = Newtonsoft.Json.Linq.JObject.Parse(result);


Newtonsoft.Json.Linq.JObject obje = Newtonsoft.Json.Linq.JObject.Parse(result);

And many other options but nothing worked, it throwing error.

Additional information:

Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.
5
  • try var options = obj[1].ToList(); ? I think you're trying to access the first item as an array when it's a string.... Commented Nov 19, 2015 at 5:48
  • This is throwing error @var obj = Newtonsoft.Json.Linq.JObject.Parse(result); line Commented Nov 19, 2015 at 5:51
  • oh right my bad, erm.... Commented Nov 19, 2015 at 5:51
  • 1
    It's throwing an exception because the root container is not an object it's an array. You want to use JToken.Parse(). Commented Nov 19, 2015 at 5:52
  • @dbc Thanks, it worked. Commented Nov 19, 2015 at 6:20

1 Answer 1

1

You have a JSON array while trying to parse is as a JSON object.

Replace

var obj = Newtonsoft.Json.Linq.JObject.Parse(result);

to

var obj = Newtonsoft.Json.Linq.JArray.Parse(result);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.