c# - Get a value from string array by search id -


i have list of values in array cmnts

"6_12_g2_text":"22","6_12_g3_text":"33","6_12_g4_text":"44"

var cmntsvalue = forms["textvalue"];     string[] cmnts = cmntsvalue.split('{','}'); 

no want search 6_12_g2_text , return 22 (for 6_12_g3_text , return 33). how can achieve this?


i got value shown in following image! json values

i insert updated code here [in second image]. kindly check not records properly

the value have json string. using json.net can parse string dictionary<string, int>, so:

var json = "{\"6_12_g2_text\":\"22\",\"6_12_g3_text\":\"33\",\"6_12_g4_text\":\"44\"}"; var dictionary = jsonconvert.deserializeobject<dictionary<string, int>>(json); 

and extract value key:

int value; if (dictionary.trygetvalue("6_12_g2_text", out value)) {     console.writeline(value); } 

edit:

after seeing actual json string, you're going have additional work:

var json = "{\"1_3_g1_text\":\"11\"}             {\"1_3_g2_text\":\"\"}             {\"6_12_g2_text\":\"test\"}             {\"6_12_g3_text\":\"\"}             {\"1_17_g1_text\":\"works\"}             {\"5_19_g2_text\":\"submitted\"}             {\"5_19_g3_text\":\"2\"}";  var jsons = json.split('{', '}').where(x => !string.isnullorwhitespace(x)); var concatenatedjson = string.format("{{{0}}}", string.join(",", jsons));  var intermidiatedict = jsonconvert.deserializeobject<dictionary<string, string>>(                                                                       concatenatedjson); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -