I have a problem deserializing this JSON response
{
"posts": {
"Pippo": {
"text": "text1",
"link": "link1"
},
"Pluto": {
"text": "text2",
"link": "link2"
}
}
}
I’m using this model
public class postModel
{
public string text { get; set; }
public string link { get; set; }
}
public class postFields
{
public postModel post { get; set; }
}
public class RootObject
{
public Dictionary<string, postFields> posts { get; set; }
}
then I deserialize this way
var deserialized = JsonConvert.DeserializeObject<RootObject>(json);
then I stop. I cannot read values because I try this
foreach (var value in deserialized)
{
new postModel
{
text = value.Value.post.text,
link = value.Value.post.link
};
}
Then I get NullReferenceException, because the name of JSON property isn’t “post” but Pippo, Pluto, etc.
Can someone help me?
Thanks to both of you; I solved this way: