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!
i insert updated code here [in second image]. kindly check
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
Post a Comment