I need to deserialize a string
like this
{ "example": { "id": "12345", "name": "blabla" } }
into a KeyValuePair<string, string>
or something similiar.
I tried:
var pair = JsonConvert.DeserializeObject<KeyValuePair<string, string>>(d["example"].ToString());
(d["example"]
returns the json string like shown above)
The result was an empty KeyValuePair<string, string>
.
Is there any way to solve this?
string json =
@"{
""example"": {
""id"": ""12345"",
""name"": ""blabla""
}
}";
var jobj = JObject.Parse(json);
var dict = jobj["example"]
.Children().Cast<JProperty>()
.ToDictionary(x => x.Name, x => (string)x.Value);
or
var dict = jobj["example"].ToObject<Dictionary<string, string>>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With