Feels like there is a one-two row solution for what I want to do: Parse a string like this:
"{\"postalcode\":\"12345\",\"postalcity\":\"SOME-CITY\",\"country\":\"UK\",\"box\":false}"
Into something like this:
string[] result = { "12345", "SOME-CITY", "UK", "false" };
Whats the simplest way to do this?
You could also use newtonsoft : http://james.newtonking.com/pages/json-net.aspx
I found another related post : JSON to string array in C#
Lib : http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx
You could use JavaScriptSerializer to serialize the json into a
dynamic
object which would allow you to access the properties via name e.g.It looks like your input string is a JSON string, for which you can use a JSON deserializer if you want. If not you can use regular-expression along with named-groups as the following:
Named groups in regular-expression are indicated by
(?<group-name>pattern)
. In the above pattern we have two named groups:key
, andvalue
which can be grabbed from theMatch
object using theGroups
indexer.