I know this question has already many answers on SO and luckily I have tried them but still unable to get my string parsed. I am getting the following JSON List from my api:
The JSON text is:
[
{"S1":"1","S2":"202010010","S30":"COCA COLA BEVERAGES PAKISTAN LTD. GUJRANWALA","S31":"Coca cola 1","D1":"2015-07-01T00:00:00","S5":"001","S32":"Local","S6":"T1","S33":"By Road","S10":""},
{"S1":"3","S2":"202010010","S30":"COCA COLA BEVERAGES PAKISTAN LTD. GUJRANWALA","S31":"Coca cola 1","D1":"2015-07-01T00:00:00","S5":"002","S32":"Innter City","S6":"T1","S33":"By Road","S10":""},
{"S1":"4","S2":"202010010","S30":"COCA COLA BEVERAGES PAKISTAN LTD. GUJRANWALA","S31":"Coca cola 1","D1":"2015-07-01T00:00:00","S5":"003","S32":"International","S6":"T2","S33":"By Sea","S10":""}
]
S1 will always be unique across the string. I want to get all S1 and show them in a spinner. And later on selection of one of S1 by user, I want to get the related data of that S1.
I have tried the answer to this question but when I tried to parse it gave me the following error:
Error reading JObject from Json reader. Current Json reader is not an object
Then I tried the following:
var jobno = JsonConvert.DeserializeObject<List<string>>(json.ToString());
as per the most voted answer to this question and got the following error:
Error reading string, Path '[0]', Line 1, Position 2.
I also tried to do something as explained in another SO question as follows:
var d = l.SelectMany (obj => obj.Select (inner => inner ["S1"].Value<string> ())).ToList ();
But it is a compile time error as:
Cannot apply indexing with [ ] to a expression of type char
How can I do that? and how can I query my JSON list later on the basis of S1?
I am generating this JSON from api as:
var result = db.Database.SqlQuery<JobNoQ>(query).ToList();
return Json(result);
I think that problem is with the JSON. May the square brackets in start and end of JSON are creating problems