Can't deserialize JSON from REST API (Wordpress) using RestSharp - c#

This has been driving me nuts - I can't deserialize some JSON I'm getting back from the Wordpress public API to get my posts. I'm using RestSharp. The data I'm getting back shows a blog post, but all the properties are null. I even used Json2CSharp to model my "Post" class after what's returned.
Here's my JSON:
{
"found":1,
"posts":[
{
"ID":2,
"site_ID":89749867,
"author":{
"ID":2988648,
"login":"loginname",
"email":false,
"name":"loginname",
"nice_name":"loginname",
"URL":"",
"avatar_URL":"https:\/\/2.gravatar.com\/avatar\/e78ee2e2f7bb75a8bc5339a6bd20194e?s=96&d=identicon&r=G",
"profile_URL":"http:\/\/en.gravatar.com\/loginname",
"site_ID":2918427
},
"date":"2015-04-20T18:16:18+00:00",
"modified":"2015-04-20T18:18:20+00:00",
"title":"Hello world!",
"URL":"https:\/\/myblog.wordpress.com\/2015\/04\/20\/hello-world\/",
"short_URL":"http:\/\/wp.me\/p64A2v-2",
"content":"<p><a href=\"https:\/\/myblog.files.wordpress.com\/2015\/04\/left_shark_5x3.png\"><img class=\"alignnone size-medium wp-image-3\" src=\"https:\/\/myblog.files.wordpress.com\/2015\/04\/left_shark_5x3.png?w=300&h=180\" alt=\"Left Shark\" width=\"300\" height=\"180\" \/><\/a><\/p>\n<p>This is your very first post. Click the Edit link to modify or delete it, or <a title=\"Direct link to Add New Post in your Dashboard\" href=\"https:\/\/wordpress.com\/post\">start a new post<\/a>. If you like, use this post to tell readers why you started this blog and what you plan to do with it.<\/p>\n<p>Happy blogging!<\/p>\n",
"excerpt":"<p>This is your very first post. Click the Edit link to modify or delete it, or start a new post. If you like, use this post to tell readers why you started this blog and what you plan to do with it. Happy blogging!<\/p>\n",
"slug":"hello-world",
"guid":"http:\/\/myblog.wordpress.com\/?p=1",
"status":"publish",
"sticky":false,
"password":"",
"parent":false,
"type":"post",
"discussion":{
"comments_open":true,
"comment_status":"open",
"pings_open":true,
"ping_status":"open",
"comment_count":0
},
"likes_enabled":true,
"sharing_enabled":true,
"like_count":0,
"i_like":0,
"is_reblogged":0,
"is_following":0,
"global_ID":"7a5ad608c4e80f7c2463eead8d34f435",
"featured_image":"https:\/\/myblog.files.wordpress.com\/2015\/04\/left_shark_5x3.png",
"post_thumbnail":{
"ID":3,
"URL":"https:\/\/myblog.files.wordpress.com\/2015\/04\/left_shark_5x3.png",
"guid":"http:\/\/myblog.files.wordpress.com\/2015\/04\/left_shark_5x3.png",
"mime_type":"image\/png",
"width":620,
"height":372
},
"format":"standard",
"geo":false,
"menu_order":0,
"page_template":"",
"publicize_URLs":[
],
"tags":{
},
"categories":{
"Uncategorized":{
"ID":1,
"name":"Uncategorized",
"slug":"uncategorized",
"description":"",
"post_count":1,
"parent":0,
"meta":{
"links":{
"self":"https:\/\/public-api.wordpress.com\/rest\/v1.1\/sites\/89749867\/categories\/slug:uncategorized",
"help":"https:\/\/public-api.wordpress.com\/rest\/v1.1\/sites\/89749867\/categories\/slug:uncategorized\/help",
"site":"https:\/\/public-api.wordpress.com\/rest\/v1.1\/sites\/89749867"
}
}
}
},
"attachments":{
"3":{
"ID":3,
"URL":"https:\/\/myblog.files.wordpress.com\/2015\/04\/left_shark_5x3.png",
"guid":"http:\/\/myblog.files.wordpress.com\/2015\/04\/left_shark_5x3.png",
"date":"2015-04-20T18:17:33+00:00",
"post_ID":2,
"file":"left_shark_5x3.png",
"mime_type":"image\/png",
"extension":"png",
"title":"Left Shark",
"caption":"",
"description":"",
"alt":"Left Shark",
"thumbnails":{
},
"height":372,
"width":620,
"exif":{
"aperture":0,
"credit":"",
"camera":"",
"caption":"",
"created_timestamp":0,
"copyright":"",
"focal_length":0,
"iso":0,
"shutter_speed":0,
"title":"",
"orientation":0
},
"meta":{
"links":{
"self":"https:\/\/public-api.wordpress.com\/rest\/v1.1\/sites\/89749867\/media\/3",
"help":"https:\/\/public-api.wordpress.com\/rest\/v1.1\/sites\/89749867\/media\/3\/help",
"site":"https:\/\/public-api.wordpress.com\/rest\/v1.1\/sites\/89749867",
"parent":"https:\/\/public-api.wordpress.com\/rest\/v1.1\/sites\/89749867\/posts\/2"
}
}
}
},
"attachment_count":1,
"metadata":[
{
"id":"9",
"key":"_thumbnail_id",
"value":"3"
}
],
"meta":{
"links":{
"self":"https:\/\/public-api.wordpress.com\/rest\/v1.1\/sites\/89749867\/posts\/2",
"help":"https:\/\/public-api.wordpress.com\/rest\/v1.1\/sites\/89749867\/posts\/2\/help",
"site":"https:\/\/public-api.wordpress.com\/rest\/v1.1\/sites\/89749867",
"replies":"https:\/\/public-api.wordpress.com\/rest\/v1.1\/sites\/89749867\/posts\/2\/replies\/",
"likes":"https:\/\/public-api.wordpress.com\/rest\/v1.1\/sites\/89749867\/posts\/2\/likes\/"
}
},
"capabilities":{
"publish_post":false,
"delete_post":false,
"edit_post":false
}
}
]
}
Here's my class (with some properties commented out so I didn't have to build those out:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace thenickwilson_SPA_NEW.Models
{
public class Post
{
public int ID { get; set; }
public int site_ID { get; set; }
//public Author author { get; set; }
public string date { get; set; }
public string modified { get; set; }
public string title { get; set; }
public string URL { get; set; }
public string short_URL { get; set; }
public string content { get; set; }
public string excerpt { get; set; }
public string slug { get; set; }
public string guid { get; set; }
public string status { get; set; }
public bool sticky { get; set; }
public string password { get; set; }
public bool parent { get; set; }
public string type { get; set; }
//public Discussion discussion { get; set; }
public bool likes_enabled { get; set; }
public bool sharing_enabled { get; set; }
public int like_count { get; set; }
public int i_like { get; set; }
public int is_reblogged { get; set; }
public int is_following { get; set; }
public string global_ID { get; set; }
public string featured_image { get; set; }
//public PostThumbnail post_thumbnail { get; set; }
public string format { get; set; }
public bool geo { get; set; }
public int menu_order { get; set; }
public string page_template { get; set; }
public List<object> publicize_URLs { get; set; }
//public Tags tags { get; set; }
//public Categories categories { get; set; }
//public Attachments attachments { get; set; }
public int attachment_count { get; set; }
//public List<Metadata> metadata { get; set; }
//public Meta3 meta { get; set; }
//public Capabilities capabilities { get; set; }
}
}
And here's the rest of my code:
[ResponseType(typeof(Post))]
public IHttpActionResult Get()
{
var client = new RestClient("http://public-api.wordpress.com/rest/v1.1/");
var request = new RestRequest("sites/{id}/posts", Method.GET);
request.AddUrlSegment("id", "myblog.wordpress.com");
request.RequestFormat = DataFormat.Json;
var response = client.Execute<List<Post>>(request);
return this.Ok(response);
}
I have a feeling it has to do with the fact that the API returns a "found" element as well as "posts", but I'm not sure. Any help would be greatly appreciated.

You are receiving an array or list of Posts wrapped in a container object, so try with this:
public class MyContainer
{
public List<Post> posts {get;set;}
}
And:
var response = client.Execute<MyContainer>(request);
You can view your json deserialized here: http://jsonviewer.stack.hu/

Related

How to generate a JSON class with dynamic name

I don't know if there is an existing name for that case, but I'm trying to retrieve data from NASA API (https://api.nasa.gov/) and I have a simple challenge to catch a list of objects near earth. Here is the JSON response I have from the GET request I do to "https://api.nasa.gov/neo/rest/v1/feed?...."
{
"links": {
"next": "http://www.neowsapp.com/rest/v1/feed?start_date=2021-07-04&end_date=2021-07-04&detailed=false&api_key=NjgpxgSbYHXyFSBI3HaOhRowtjMZgAKv2t4DMRym",
"prev": "http://www.neowsapp.com/rest/v1/feed?start_date=2021-07-02&end_date=2021-07-02&detailed=false&api_key=NjgpxgSbYHXyFSBI3HaOhRowtjMZgAKv2t4DMRym",
"self": "http://www.neowsapp.com/rest/v1/feed?start_date=2021-07-03&end_date=2021-07-03&detailed=false&api_key=NjgpxgSbYHXyFSBI3HaOhRowtjMZgAKv2t4DMRym"
},
"element_count": 6,
"near_earth_objects": {
"2021-07-03": [
{
"links": {
"self": "http://www.neowsapp.com/rest/v1/neo/3701710?api_key=NjgpxgSbYHXyFSBI3HaOhRowtjMZgAKv2t4DMRym"
},
"id": "3701710",
"neo_reference_id": "3701710",
"name": "(2014 WF497)",
"nasa_jpl_url": "http://ssd.jpl.nasa.gov/sbdb.cgi?sstr=3701710",
"absolute_magnitude_h": 20.23,
"estimated_diameter": {
"kilometers": {
}
And that's the way it is built in Visual Studio (using the Special Paste option for JSON)
public class NearEarthObject
{
public Links links { get; set; }
public int element_count { get; set; }
public Near_Earth_Objects near_earth_objects { get; set; }
}
public class Links
{
public string next { get; set; }
public string prev { get; set; }
public string self { get; set; }
}
public class Near_Earth_Objects
{
public _20210703[] _20210703 { get; set; }
}
public class _20210703
{
public Links1 links { get; set; }
public string id { get; set; }
public string neo_reference_id { get; set; }
public string name { get; set; }
public string nasa_jpl_url { get; set; }
public float absolute_magnitude_h { get; set; }
public Estimated_Diameter estimated_diameter { get; set; }
public bool is_potentially_hazardous_asteroid { get; set; }
public Close_Approach_Data[] close_approach_data { get; set; }
public bool is_sentry_object { get; set; }
}
The question is, inside of the element "near_earth_objects", there is an element called "2021-07-03" (the date of the data I requested), the problem is that I am trying to include it into a DataGridView made in .NET C# (Windows Forms, but that doesn't matters here, I think) and the user wants to get the information by date. So, "2021-07-03" is a valid member just for one day, and the user should be able to get data from multiple days.
So, is there a way in C# to get all child objects inside of near_earth_objects without knowing their names since there will be the option to search for asteroids from date X to Y in my application?
Using System.Text.Json
The API response will map to the following classes
public class Neo
{
public Links Links { get; set; }
public int ElementCount { get; set; }
public Dictionary<string, List<NearEarthObject>> NearEarthObjects { get; set; }
}
public class Links
{
public string Next { get; set; }
public string Prev { get; set; }
public string Self { get; set; }
}
public class NearEarthObject
{
public Links Links { get; set; }
public string Id { get; set; }
public string Name { get; set; }
// Other properties
}
The NearEarthObjects is simply a Dictionary, where the key is the formatted date and value is a List containing NearEarthObject
The PropertyNamingPolicy will allow us to support the API's underscore property naming convention.
public class UnderscoreNamingPolicy : JsonNamingPolicy
{
public override string ConvertName(string name)
{
return name.Underscore();
}
}
Example usage
// using using System.Text.Json;
var response = await new HttpClient().GetStringAsync(url);
var neo = JsonSerializer.Deserialize<Neo>(response, new JsonSerializerOptions
{
PropertyNamingPolicy = new UnderscoreNamingPolicy()
});
foreach(var neos in neo.NearEarthObjects)
{
Console.WriteLine(neos.Key);
}
use System.Text.Json, JsonNamingPolicy
demo code
public class DynamicNamePolicy : JsonNamingPolicy
{
public override string ConvertName(string name)
{
var today = DateTime.Today.ToString("yyyy-MM-dd");
if (name.Equals("DateData")) //model property name
return today; //convert to json string property name
return name;
}
}
//data deserialize
string data = ""; //json string
var obj = JsonSerializer.Deserialize<NearEarthObject>(data, new JsonSerializerOptions
{
PropertyNamingPolicy = new DynamicNamePolicy(),
});

Not able validate data condition based on the json element attribute value from a json using c#

I have a json file, where i have to validate a json attribute element value based on another json element attribute value. But if there json elements with the same name. It always takes the last value always instead of parsing the json data fully. Please guide me.
Below the sample json file
{
"PLMXML":{
"language":"en-us",
"author":"Developer",
"date":"2020-05-22",
"traverseRootRefs":"#id6",
"Operation":{
"id":"id21",
"subType":"BS4_BaOP",
"catalogueId":"70700000209604"
},
"Operation":{
"id":"id28",
"subType":"BS4_BaOP",
"catalogueId":"70700000209603"
},
"OperationRevision":{
"id":"id6",
"subType":"BS4_BaOPRevision",
"masterRef":"#id21",
"revision":"A1"
}
}
}
And below the code which im trying to use
public void Readjsonfile(string jsondata)
{
var message = JsonConvert.DeserializeObject<plmxmldatamodel>(jsondata);
if (String.Equals(message.PLMXML.traverseRootRefs.Substring(1), message.PLMXML.OperationRevision.id))
{
Console.WriteLine("Condtion1");
if (String.Equals(message.PLMXML.OperationRevision.masterRef.Substring(1), message.PLMXML.Operation.id))
{
Console.WriteLine("Condition_2");
//Do something based on the condtion
}
}
}
public class Operation
{
public string id { get; set; }
public string subType { get; set; }
public string catalogueId { get; set; }
}
public class OperationRevision
{
public string id { get; set; }
public string subType { get; set; }
public string masterRef { get; set; }
}
public class PLMXML
{
public string language { get; set; }
public string author { get; set; }
public string date { get; set; }
public string traverseRootRefs { get; set; }
public Operation Operation { get; set; }
public OperationRevision OperationRevision { get; set; }
}
public class plmxmldatamodel
{
public PLMXML PLMXML { get; set; }
}
When i try to dedug this in the second if condtion, the value for message.PLMXML.Operation.id is always id28 , because of which second if condition fails. While the first if condition is passed as there is only one message.PLMXML.OperationRevision.id. i wanted behaviour where it would check complete json data and check if message.PLMXML.Operation.id with value id21 is present or not , So my data gets passed. Please kindly guide me here.I am very new to C# here.
From my observation you have couple of issues.
What happen you have double keys, and your parser taking the last value not the first one.
First of all your json should be corrected. I assume you have access to change your json and operation should be an array like follow:
{
"PLMXML":{
"language":"en-us",
"author":"Developer",
"date":"2020-05-22",
"traverseRootRefs":"#id6",
"Operations":[
{
"id":"id21",
"subType":"BS4_BaOP",
"catalogueId":"70700000209604"
},
{
"id":"id28",
"subType":"BS4_BaOP",
"catalogueId":"70700000209603"
}
],
"OperationRevision":{
"id":"id6",
"subType":"BS4_BaOPRevision",
"masterRef":"#id21",
"revision":"A1"
}
}
}
When array in place than use an online tool like to validate your json and use this tool to create a model.
Your model will be like this:
public partial class PlmxmlDataModel
{
[JsonProperty("PLMXML")]
public Plmxml Plmxml { get; set; }
}
public partial class Plmxml
{
[JsonProperty("language")]
public string Language { get; set; }
[JsonProperty("author")]
public string Author { get; set; }
[JsonProperty("date")]
public DateTimeOffset Date { get; set; }
[JsonProperty("traverseRootRefs")]
public string TraverseRootRefs { get; set; }
[JsonProperty("Operations")]
public Operation[] Operations { get; set; }
[JsonProperty("OperationRevision")]
public OperationRevision OperationRevision { get; set; }
}
public partial class OperationRevision
{
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("subType")]
public string SubType { get; set; }
[JsonProperty("masterRef")]
public string MasterRef { get; set; }
[JsonProperty("revision")]
public string Revision { get; set; }
}
public partial class Operation
{
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("subType")]
public string SubType { get; set; }
[JsonProperty("catalogueId")]
public string CatalogueId { get; set; }
}
And your method like this:
public void Readjsonfile(string jsondata)
{
var message = JsonConvert.DeserializeObject<PlmxmlDataModel>(jsondata);
if (String.Equals(message.Plmxml.TraverseRootRefs.Substring(1), message.Plmxml.OperationRevision.Id))
{
Console.WriteLine("Condtion1");
if (String.Equals(message.Plmxml.OperationRevision.MasterRef.Substring(1), message.Plmxml.Operations[0].Id))
{
Console.WriteLine("Condition_2");
//Do something based on the condtion
}
}
}
Now in your method I am looking for array index 0 with contain id 28, but if you are look for id 28 in any of the array then you can do some thing like:
if (message.Plmxml.Operations.Any(e => e.Id == message.Plmxml.OperationRevision.MasterRef.Substring(1)))

nested json deserialization - need another set of eyes

I have been trying to get this json to deserialize for two days now using RestSharp. I have gone through the RestSharp github site, looked at countless examples, and spent much time here on Stack Overflow to try and find the answer to no avail. My code had previously worked perfectly but the vendor changed their API version and I was forced to do an update to keep using the application for my legal practice. My json is as follows(client info has been removed and replaced with generic info):
{
"data":[
{
"id":1035117666,
"client":
{
"id":905422394,
"name":"client1"
},
"display_number":"11-00012",
"description":"General",
"practice_area":
{
"id":4269978,
"name":"Business"
},
"status":"Open",
"open_date":"2011-12-14",
"close_date":null,
"billing_method":"hourly"
},
{
"id":1035117768,
"client":
{
"id":905422506,
"name":"client2"
},
"display_number":"12-00037",
"description":"HOA",
"practice_area":
{
"id":4269978,
"name":"Business"
},
"status":"Open",
"open_date":"2012-08-07",
"close_date":null,
"billing_method":"hourly"
}
],
"meta":
{
"paging":
{
"next":"https://app.goclio.com/api/v4/matters.json?fields=id%2C+client%7Bid%2C+name%7D%2C+display_number%2C+description%2C+practice_area%7Bid%2C+name%7D%2C+status%2C+open_date%2C+close_date%2C+billing_method&limit=2&page_token=BAh7BjoLb2Zmc2V0aQc%3D--b1ea3eba20c8acefbcdfc7868debd1e0ee630c64&status=Open"
},
"records":91
}
}
I built the following schema within my c# code:
public class MatterList
{
public List<Matter> matters { get; set; }
public Meta meta { get; set; }
}
public class Meta
{
public Paging paging { get; set; }
public int records { get; set; }
}
public class Paging
{
public string previous { get; set; }
public string next { get; set; }
}
[DeserializeAs(Name = "data")]
public class Matter
{
public int id { get; set; }
public Client client { get; set; }
public string display_number { get; set; }
public string description { get; set; }
public PracticeArea practice_area { get; set; }
public string status { get; set; }
public DateTime open_date { get; set; }
public DateTime close_date { get; set; }
public string billing_method { get; set; }
public string type = "matter";
}
public class PracticeArea
{
public int id { get; set; }
public string name { get; set; }
}
public class Client
{
public int id { get; set; }
public string name { get; set; }
}
When I run the RestSharp deserialize method I am sending the result to an object of type MatterList using the following line of code
MatterList matterList = jsonHandler.Deserialize<MatterList>(response);
I have so far attempted to deserialize without the Meta or Paging POCO classes with the accompanying change to the MatterList class (taking out the Meta property).
I have tried with and without the [DeserializeAs(Name="data")] directive.
I have tried to set the RootElement of the json response prior to deserialization.
I have tried to shorthand the deserialization by combining it with the Execute request code
IRestResponse<MatterList> matterList = client.Execute<MatterList>(request);
I have created a container class called MatterContainer which I placed between MatterList and Matter classes in the schema:
public class MatterList
{
public List<MatterContainer> matters { get; set; }
}
public class MatterContainer
{
public Matter matter { get; set; }
}
public class Matter
{
public int id { get; set; }
public Client client { get; set; }
public string display_number { get; set; }
public string description { get; set; }
public PracticeArea practice_area { get; set; }
public string status { get; set; }
public DateTime open_date { get; set; }
public DateTime close_date { get; set; }
public string billing_method { get; set; }
public string type = "matter";
}
I know I am getting the json response back from the server correctly so my request is proper and MatterList is not null after deserialization. The problem is that I cannot get the deserialization to actually populate the List matters within the MatterList class.
I have been looking at this off and on for two days and cannot get past this hurdle. If anyone sees what I did wrong I would greatly appreciate the insight, I am at a point where I cannot progress further with my application.
Thanks!
I think your [DeserializeAs(Name = "data")] attribute is in the wrong place. Try putting it in the root class instead:
public class MatterList
{
[DeserializeAs(Name = "data")]
public List<Matter> matters { get; set; }
public Meta meta { get; set; }
}
alternatively, try renameing that property to data

How to set up class for json?

I am working with opentdb.com api and have no idea how to access data in this json:
{
"response_code":0,
"results": [
{
"category":"Animals",
"type":"multiple",
"difficulty":"easy",
"question":"What is the scientific name for modern day humans?",
"correct_answer":"Homo Sapiens",
"incorrect_answers":[
"Homo Ergaster",
"Homo Erectus",
"Homo Neanderthalensis"
]
},
{
"category":"Entertainment: Cartoon & Animations",
"type":"multiple",
"difficulty":"easy",
"question":"Who voices for Ruby in the animated series RWBY?",
"correct_answer":"Lindsay Jones",
"incorrect_answers":[
"Tara Strong",
"Jessica Nigri",
"Hayden Panettiere"
]
}
]
}
I am using Newtonsoft.Json and i tried this with only 1 Question but im geting an error that says that key value is wrong..
class Trivia
{
public Trivia(string json)
{
JObject jObject = JObject.Parse(json);
JToken jresults = jObject["results"];
category = (string)jresults["category"];
type = (string)jresults["type"];
difficulty = (string)jresults["difficulty"];
question = (string)jresults["question"];
correct_answer = (string)jresults["correct_answer"];
incorrect_answers = jresults["incorrect_answers"].ToArray();
}
public string category { get; set; }
public string type { get; set; }
public string difficulty { get; set; }
public string question { get; set; }
public string correct_answer { get; set; }
public Array incorrect_answers { get; set; }
}
Copy from json text and in new class in visual studio Edit-->Paste Special-->Paste JSON As Classes
public class Rootobject
{
public int response_code { get; set; }
public Result[] results { get; set; }
}
public class Result
{
public string category { get; set; }
public string type { get; set; }
public string difficulty { get; set; }
public string question { get; set; }
public string correct_answer { get; set; }
public string[] incorrect_answers { get; set; }
}
using namespace
using Newtonsoft.Json;
response is value get from your service
var outdeserialized = JsonConvert.DeserializeObject<Rootobject>(response);

Parse JSON object in C#

I use JSON.NET and I would like to parse the following object which I get from a WebService. Can someone post an example on how to do that?
#"{""MessageType"":0,
""Message"":""Success"",
""Value"":[
{""listId"":1,
""listName"":""DemoList"",
""itemInList"":[
{
""fromDate"":""\/Date(1228946400000)\/"",
""fromLocation"":null,
""toLocation"":null,
""originalRequest"":""water"",
""creationDate"":""\/Date(1339448400000)\/"",
""typeId"":1
},
{
""fromDate"":null,
""fromLocation"":null,
""toLocation"":null,
""originalRequest"":""gala"",
""creationDate"":""\/Date(1304370000000)\/"",
""typeId"":1
}
]}
]}"
JSON Object
{
"MessageType":0,
"Message":"UserLists",
"Value":
[
{
"listId":1,
"listName":"DemoList",
"itemInList"
[
{
"fromDate":"\/Date(1228946400000)\/",
"fromLocation":null,
"toLocation":null,
"originalRequest":"water",
"creationDate":"\/Date(1339448400000)\/",
"typeId":1
},
{
"fromDate":null,
"fromLocation":null,
"toLocation":null,
"originalRequest":"gala",
"creationDate":"\/Date(1304370000000)\/",
"typeId":1
}
],
"numberOfItems":2
}
]
}
Thanks.
You need to create some entity like this:
public class Entity
{
public int MessageType { get; set; }
public string Message { get; set; }
public List<EntityValue> Value { get; set; }
}
public class EntityValue
{
public int listId { get; set; }
public string listName { get; set; }
public List<ItemInList> itemInList { get; set; }
}
public class ItemInList
{
public DateTime? fromDate { get; set; }
public string fromLocation { get; set; }
public string toLocation { get; set; }
public string originalRequest { get; set; }
public DateTime creationDate { get; set; }
public int typeId { get; set; }
}
The entity must has the same structure like the json data.
And you can call the Method:
JsonConvert.DeserializeObject<Entity>(json);
If it has any exception,you need to adjust the entities until it works.
Please read the below link for parsi in metro style application.
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh770287.aspx

Categories

Resources