I'm new with JSON.NET and I'm trying to deserialize a JSON string to a simple .NET object. Here is a snippet of my code:
public void DeserializeFeed(string feed)
{
JsonSerializer ser = new JsonSerializer();
Post deserializedPost = JsonConvert.DeserializeObject<Post>(feed);
if (deserializedPost == null)
MessageBox.Show("JSON ERROR !");
else
{
MessageBox.Show(deserializedPost.titre);
}
}
When I do
MessageBox.Show(deserializedPost.titre);
I always get this error:
Value can not be null.
Here is my object that I want to fill with the retrieved JSON element:
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace MeltyGeeks
{
public class Post
{
public String titre { get; set; }
public String aresum { get; set; }
// Constructor
public Post()
{
}
}
}
And here is a snippet of my JSON string:
{"root_tab":{"tab_actu_fil":{"data":[{"c_origine":"MyApp",
"titre":"title of first article",
"aresum":"this is my first Article
"tab_medias":{"order":{"810710":{"id_media":810710,"type":"article","format":"image","height":138,"width":300,"status":null}}}},
Postclass against which you deserialize.