I have the following string:
{"key1":"value1","key2":"value2,some other part of value2"}
I can use the following long syntax to split this:
var s = someString.Split(new[] {"\",\""}, StringSplitOptions.RemoveEmptyEntries);
var firstEntryValue = s[0].Split(':')[1];
var secondEntryValue = s[1].Split(':')[1];
Since this string is basically a Dictionary<string,string>
, how can I pull the whole thing into that type in basically one line?
I've seen something like this:
var s = someString.Split(new[] {"\",\""}, StringSplitOptions.RemoveEmptyEntries)
.Select(p => p.Split(':'))
.ToDictionary(split => split[0], split => split[1]);
But it throws and index out of bounds error. Is there some similar syntax that will work?