I have a simple WinForm program that does a WebRequest to a server, the response is a string looking like:
{"a":"foo","b":"bar"}
How do convert this string to a dictionary? (Dictionary<string, string>
). Is there a built-in function I can use?
I have a simple WinForm program that does a WebRequest to a server, the response is a string looking like:
{"a":"foo","b":"bar"}
How do convert this string to a dictionary? (Dictionary<string, string>
). Is there a built-in function I can use?
Use a library like JSON.NET:
var dictionary = JsonConvert.DeserializeObject<IDictionary<string, string>>(json)
var sourve = @"{"a":"foo","b":"bar"}";
Dictionary<string, string> result = JsonConvert.DeserializeObject<Dictionary<string, string>>(source);
If you can add two assemblies:
You can use this code:
string html = "{\"a\":\"foo\",\"b\":\"bar\"}";
JavaScriptSerializer jss = new JavaScriptSerializer();
var dict = jss.Deserialize<Dictionary<string, string>>(html);