mdc mdc - 1 year ago 76
JSON Question

Parse this json string to string array c#

Feels like there is a one-two row solution for what I want to do:
Parse a string like this:


Into something like this:

string[] result = { "12345", "SOME-CITY", "UK", "false" };

Whats the simplest way to do this?

Answer Source
string json = "{\"postalcode\":\"12345\",\"postalcity\":\"SOME-CITY\",\"country\":\"UK\",\"box\":false}";

var dict = new JavaScriptSerializer().Deserialize<Dictionary<string,object>>(json);
var postalCode = dict["postalcode"];

//Array is also possible
string[] result = dict.Select(kv => kv.Value.ToString()).ToArray();