c# - List values by key in deserialized json object -


so define

public class globals {     public list<object> var { get; set; } } 

my json i'm sending so

{"var":[{"test1":"1","test2","2","test3","3"}],"morejson":"blahblahblah}

so lets have , pretend appendtextbox writing textbox in separate thread

void getmedata() {     var commands = jsonparser.deserialize<globals>(json);      appendtextbox(commands.description[0].tostring());      appendtextbox(commands.description.count.tostring()); } 

appendtextbox(commands.description.count.tostring()); works , shows count

however cannot seem print values preferably key. way set gives following output

system.collections.generic.dictionary`2[system.string,system.object]` 

any suggestions?

you can use list of dictionary use instead of object access using :

public class globals {     public list<dictionary<string, string>> var { get; set; } } 

then, json

{"var":[{"test1":"1","test2","2","test3","3"}, {"anykey1": "anyvalue1", "anykey2": "anyvalue2"}, {}, {"1": "2"}], "morejson": "blahblahblah"} 

will convert list of length 4. each key represent dictionary<string, string>.

for example, if this:

foreach (var keyvaluepair in commands[1]) {      console.writeline("{0} => {1}", keyvaluepair.key, keyvaluepair.value); } 

you get

anykey1 => anyvalue1 anykey2 => anyvalue2 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -