How to get the values and keys from a json deserialized/parsed string in C#? -
i have cookie string array put c# looks this:
questionnaire a:
[{"8872":"yes", "9900":"bob", "2222":"sagat"}]
where numbers number question id db (key) , value customers response. time questionnaire doesn't have same question ids in it, cannot make model read ids.
example: questionnaire b:
[{"2222":"no","6756":"brown","5416":"jerry","4684":"tom"}]
all want pull users response question question 9900.
this work have done far , crashing:
c#
var arrstring = ""[{\"8872\" : \"yes\",\"9900\" : \"bob\",\"2222\" : \"sagat\"}]" var arr = jsonconvert.deserializeobject(arrstring); foreach (var attendee in (ienumerable) attendeearray) { var theresponseofquestion9900 = attendee.9900 }
attendee.9900 give me error @ '.' unexpected token.
i think because reading 9900 double instead of key.
you can deserialize list<dictionary<int, string>>
var res = jsonconvert.deserializeobject<list<dictionary<int, string>>>(json);
now, have list of dictionaries....
Comments
Post a Comment