Extract few values from JSON Array - c#

The problem I am facing is that I am getting 0's for the values I ask for in the JSON.
I recently asked a question here about getting specific values from a JSON array response that come from an API.
Now I have a new JSON response from a different route and in there I want one values and its called EntityId its places in a block of Entity See the code for more details, I would like to grab that from this response and place them in a list or Array because it tells me who submitted the assignment in D2L.
UPDATE- After getting comments from a user I used JSON to C# tool to create the full class with all the values but I still get the values as 0,0,0,0.
Right now I am getting 0,0,0,0 values and not getting the actual values if it's possible I would like to grab the whole block on Entity.
JSON
[
{
"Entity": {
"DisplayName": "FullName",
"EntityId": 123,
"EntityType": "User",
"Active": true
},
"Status": 1,
"Feedback": null,
"Submissions": [
{
"Id": 27,
"SubmittedBy": {
"Identifier": "123",
"DisplayName": "FullName"
},
"SubmissionDate": "2019-08-01T15:25:04.130Z",
"Comment": {
"Text": "",
"Html": ""
},
"Files": [
{
"IsRead": false,
"IsFlagged": false,
"IsDeleted": false,
"FileId": 1245,
"FileName": "1.2.10.png",
"Size": 144407
},
{
"IsRead": false,
"IsFlagged": false,
"IsDeleted": false,
"FileId": 292,
"FileName": "1.3.8.png",
"Size": 127869
}
]
}
],
"CompletionDate": "2019-08-01T15:25:04.130Z"
},
{
"Entity": {
"DisplayName": "FullName",
"EntityId": 123,
"EntityType": "User",
"Active": true
},
"Status": 1,
"Feedback": null,
"Submissions": [
{
"Id": 41,
"SubmittedBy": {
"Identifier": "123",
"DisplayName": "FullName"
},
"SubmissionDate": "2019-08-03T03:31:43.807Z",
"Comment": {
"Text": " \nAlex",
"Html": "<p></p>\n<p>Alex</p>"
},
"Files": [
{
"IsRead": false,
"IsFlagged": false,
"IsDeleted": false,
"FileId": 313,
"FileName": "Capture 1.2.10 Questions.PNG",
"Size": 97722
}
]
}
],
"CompletionDate": "2019-08-03T03:31:43.807Z"
}
]
Classes:
public class Entity
{
public string DisplayName { get; set; }
public int EntityId { get; set; }
public string EntityType { get; set; }
public bool Active { get; set; }
}
public class SubmittedBy
{
public string Identifier { get; set; }
public string DisplayName { get; set; }
}
public class Comment
{
public string Text { get; set; }
public string Html { get; set; }
}
public class File
{
public bool IsRead { get; set; }
public bool IsFlagged { get; set; }
public bool IsDeleted { get; set; }
public int FileId { get; set; }
public string FileName { get; set; }
public int Size { get; set; }
}
public class Submission
{
public int Id { get; set; }
public SubmittedBy SubmittedBy { get; set; }
public DateTime SubmissionDate { get; set; }
public Comment Comment { get; set; }
public IList<File> Files { get; set; }
}
public class Example
{
public Entity Entity { get; set; }
public int Status { get; set; }
public object Feedback { get; set; }
public IList<Submission> Submissions { get; set; }
public DateTime CompletionDate { get; set; }
}
Code:
var request = new RestRequest(string.Format(Link));
request.Method = Method.GET;
authenticator.Authenticate(client, request);
var response = client.Execute(request);
var thisasa = JsonConvert.DeserializeObject<List<Example>>
(response.Content).Select(
o => o.Identifier).ToList();

The Example data model shown in your question already can be used to successfully deserialize the JSON shown. All that's left is to pick out the Entity.EntityId property via a Select:
var thisasa = JsonConvert.DeserializeObject<List<Example>>(response.Content)
.Select(o => o.Entity.EntityId)
.ToList();
Demo fiddle #1 here.
Incidentally, if you only need Entity.EntityId you could simplify your data model as follows:
public class Entity
{
public int EntityId { get; set; }
}
public class Example
{
public Entity Entity { get; set; }
}
Demo fiddle #2 here.
(As an aside, since your Example class corresponds to the documented object Dropbox.EntityDropbox, you might want to rename your type to EntityDropbox for clarity.)

Related

Filter JSON response from an API call

Basically I am making an api call I receive the api call in a JSON format and I need to basically filter through the api call to only return the value's for sys_name. I am unsure how to accomplish this as my JsonConvert.DeserializeObject<>() is coming back blank.
{
try
{
using (HttpClient client = GetClient())
{
var response = client.GetAsync("this is the api call but I cleared it as you wont be able to use anyway");
response.Wait();
if (response.Result.IsSuccessStatusCode)
{
var result = await response.Result.Content.ReadAsStringAsync();
Result items = JsonConvert.DeserializeObject<Result>(result);
Console.WriteLine(items.SysName);
return null;
}
};
} catch (Exception ex)
{
_logger.LogWarning(ex, $"Failed to retrieve requested Table |{ex.Message}");
Console.WriteLine(ex.Message);
}
return null;
}
and then I have a wrapper class that I made using jsonutils.com
{
[JsonProperty("link")]
public string Link { get; set; }
[JsonProperty("value")]
public string Value { get; set; }
}
public class SysPackage
{
[JsonProperty("link")]
public string Link { get; set; }
[JsonProperty("value")]
public string Value { get; set; }
}
public class SysScope
{
[JsonProperty("link")]
public string Link { get; set; }
[JsonProperty("value")]
public string Value { get; set; }
}
public class Result
{
[JsonProperty("rec_misc")]
public string RecMisc { get; set; }
[JsonProperty("question")]
public Question Question { get; set; }
[JsonProperty("sys_mod_count")]
public string SysModCount { get; set; }
[JsonProperty("sys_updated_on")]
public string SysUpdatedOn { get; set; }
[JsonProperty("sys_tags")]
public string SysTags { get; set; }
[JsonProperty("sys_class_name")]
public string SysClassName { get; set; }
[JsonProperty("published_ref")]
public string PublishedRef { get; set; }
[JsonProperty("sys_id")]
public string SysId { get; set; }
[JsonProperty("sys_package")]
public SysPackage SysPackage { get; set; }
[JsonProperty("inactive")]
public string Inactive { get; set; }
[JsonProperty("sys_update_name")]
public string SysUpdateName { get; set; }
[JsonProperty("sys_updated_by")]
public string SysUpdatedBy { get; set; }
[JsonProperty("sys_created_on")]
public string SysCreatedOn { get; set; }
[JsonProperty("sys_name")]
public string SysName { get; set; }
[JsonProperty("sys_scope")]
public SysScope SysScope { get; set; }
[JsonProperty("text")]
public string Text { get; set; }
[JsonProperty("value")]
public string Value { get; set; }
[JsonProperty("sys_created_by")]
public string SysCreatedBy { get; set; }
[JsonProperty("misc")]
public string Misc { get; set; }
[JsonProperty("order")]
public string Order { get; set; }
[JsonProperty("sys_policy")]
public string SysPolicy { get; set; }
}
public class Wrapper
{
[JsonProperty("result")]
public IList<Result> Result { get; set; }
}
}
Showing that items comes up empty
JSON format I had to edit some of the values and obv its way longer but this should give an idea
{
"result": [
{
"rec_misc": "0",
"question": {
"link": "link goes here",
"value": "494a2"
},
"sys_mod_count": "1",
"sys_updated_on": "2021-11-15 17:18:10",
"sys_tags": "",
"sys_class_name": "question_choice",
"published_ref": "",
"sys_id": "",
"sys_package": {
"link": "link goes here",
"value": "global"
},
"inactive": "false",
"sys_update_name": "question_choice_",
"sys_updated_by": "someone ",
"sys_created_on": "2021-11-15 17:17:35",
"sys_name": "BG Info",
"sys_scope": {
"link": "link goes here",
"value": "global"
},
"text": "BG Info",
"value": "BG Info",
"sys_created_by": "someone",
"misc": "0",
"order": "300",
"sys_policy": ""
},
{
"rec_misc": "0",
"question": {
"link": "link goes here",
"value": "5b42"
},
"sys_mod_count": "0",
"sys_updated_on": "2021-04-14 06:56:39",
"sys_tags": "",
"sys_class_name": "question_choice",
"published_ref": "",
"sys_id": "05c2d",
"sys_package": {
"link": "link goes here",
"value": "global"
},
"inactive": "false",
"sys_update_name": "question_choice_",
"sys_updated_by": "someone",
"sys_created_on": "2021-04-14 06:56:39",
"sys_name": "Baseline (Developer Plus Build Mgr)",
"sys_scope": {
"link": "link goes here",
"value": "global"
},
"text": "Baseline (Developer Plus Build Mgr)",
"value": "baseline",
"sys_created_by": "someone",
"misc": "0",
"order": "300",
"sys_policy": ""
},
Use
Wrapper results = JsonConvert.DeserializeObject<Wrapper>(result);
The response is coming as an array so you have to map the data properly.

Deserializing object leads to null variables inside object

I am trying to deserialize a object in C#, using NewtonSoft framework fro json handling. This is my code.
Brief Explanation
Essentially, I am creating a api call to the login endpoint to authenticate my user (this works), I need to extract the bearer token from the api call which returns a UserResponseDTO, this DTO contains the AuthToken attribute which I need to access, to pass my test cases.
Now this is the code of my test case.
[Fact]
public async void SuccessfulGetUserDetails()
{
//Arrange
//Arrange
var content = JsonConvert.SerializeObject(success); //Prepare payload
var buffer = System.Text.Encoding.UTF8.GetBytes(content);
var byteContent = new ByteArrayContent(buffer);
byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); //Set type to Json
//Act
var result = await _client.PostAsync("http://localhost:5000/api/Security/login", byteContent); //Send Request
var jsonstring = result.Content.ReadAsStringAsync().Result; //Get JSON String
UserResponseDTO dto = new UserResponseDTO();
dto = JsonConvert.DeserializeObject<UserResponseDTO>(jsonstring); //Deserialize
Assert.Equal(dto,null);
}
Now my last Assert check is to check if the DTO object is null....its not, but the values inside it are.
This is the UserResponseDTO
public class UserResponseDTO
{
public int UserId { get; set; }
public string AuthToken { get; set; }
public string UserName { get; set; }
public string FullName { get; set; }
public string Unit { get; set; }
public string IsActive { get; set; }
public string Mobile { get; set; }
public string Email { get; set; }
public List<UserRole> UserRole { get; set; }
public List<Menus> Menus { get; set;}
}
public class UserRole
{
public Role Role { get; set; }
}
public class Role
{
public int RoleId { get; set; }
public int ApplicationId { get; set; }
public string RoleDescription { get; set; }
public virtual List<RolePermission> RolePermission { get; set; }
public List<RoleMenu> RoleMenu { get; set; }
}
public class RoleMenu
{
public int RoleMenuId { get; set; }
public bool IsDefault { get; set; }
public virtual Menu Menu { get; set; }
}
public class RolePermission
{
public int RolePermissionId { get; set; }
public Permission Permission { get; set; }
}
public class Permission
{
public int PermissionId { get; set; }
public string Name { get; set; }
}
public class Menu
{
public int MenuId { get; set; }
public string Urlprefix { get; set; }
public string Url { get; set; }
public string Description { get; set; }
public bool IsParent { get; set; }
public bool IsActive { get; set; }
public int? ParentMenu { get; set; }
public string HtmlBody { get; set; }
public string CssClass { get; set; }
}
public class Menus
{
public bool isExternal { get; set; }
public string cssClass { get; set; }
public string routeLink { get; set; }
public string menuText { get; set; }
public List<SubMenuItems> subMenuItems { get; set; } = new List<SubMenuItems>();
}
public class SubMenuItems
{
public string routeLink { get; set; }
public string menuText { get; set; }
public string cssClass { get; set; }
}
Last but not least, I have noticed
THE CORRECT Json String is being returned however it is not being deserializd properly into a UserResponseDTO Object. And the values inside the DTO are all null.
What can I do to resolve this issue?
He is the JSON that is being returned in JSON String
Code of JSON as requested
"loginResponse": "Authenticated",
"userDetails": {
"userId": 3,
"authToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6ImFkbWluIiwibmJmIjoxNjIzMDM2OTkxLCJleHAiOjE2MjMwNDA1OTEsImlhdCI6MTYyMzAzNjk5MX0.wwIJ93syFnpcvjtw_Sj1s4uCtYPUtoROmwF3jkDZWo0",
"userName": "admin",
"fullName": "REDACTED",
"unit": null,
"isActive": "1",
"mobile": "+REDACTED",
"email": "REDACTED",
"userRole": [
{
"role": {
"roleId": 1,
"applicationId": 1,
"roleDescription": "Administrator",
"rolePermission": [
{
"rolePermissionId": 0,
"permission": {
"permissionId": 1,
"name": "CanApprove"
}
},
{
"rolePermissionId": 0,
"permission": {
"permissionId": 2,
"name": "CanReject"
}
},
{
"rolePermissionId": 0,
"permission": {
"permissionId": 3,
"name": "CanReview"
}
},
{
"rolePermissionId": 0,
"permission": {
"permissionId": 4,
"name": "CanDownload"
}
}
],
"roleMenu": [
{
"roleMenuId": 1,
"isDefault": true,
"menu": {
"menuId": 1,
"urlprefix": "UI",
"url": "worklist",
"description": "Menu",
"isParent": true,
"isActive": true,
"parentMenu": null,
"htmlBody": "<li><i class=\"fa fa-cog\"></i><span class=\"nav-label\">HEADING</span></li>",
"cssClass": "receipt"
}
},
{
"roleMenuId": 2,
"isDefault": false,
"menu": {
"menuId": 2,
"urlprefix": "UI",
"url": "reports",
"description": "Link 1",
"isParent": false,
"isActive": true,
"parentMenu": 1,
"htmlBody": "<li><i class=\"fa fa-plug\"></i><span class=\"nav-label\">HEADING</span></li>",
"cssClass": "fact_check"
}
},
{
"roleMenuId": 3,
"isDefault": false,
"menu": {
"menuId": 3,
"urlprefix": "UI",
"url": "generatefile",
"description": "Link 2",
"isParent": false,
"isActive": true,
"parentMenu": 1,
"htmlBody": "<li>HEADING</li>",
"cssClass": "file_present"
}
},
{
"roleMenuId": 9,
"isDefault": false,
"menu": {
"menuId": 4,
"urlprefix": "UI",
"url": "globalsearch",
"description": "Global Search",
"isParent": true,
"isActive": true,
"parentMenu": null,
"htmlBody": "<li>HEADING</li>",
"cssClass": "search"
}
}
]
}
}
],
"menus": [
{
"isExternal": false,
"cssClass": "receipt",
"routeLink": "worklist",
"menuText": "Menu",
"subMenuItems": [
{
"routeLink": "reports",
"menuText": "Link 1",
"cssClass": "fact_check"
},
{
"routeLink": "generatefile",
"menuText": "Link 2",
"cssClass": "file_present"
}
]
},
{
"isExternal": false,
"cssClass": "search",
"routeLink": "globalsearch",
"menuText": "Global Search",
"subMenuItems": []
}
]
}
}
Your json does not match the UserResponseDTO, you need add matched model like:
public class ResponseModel
{
public string LoginResponse { get; set; }
public UserResponseDTO UserDetails { get; set; }
}
If you do not want to add the response model, you need modify the json string to read userDetails:
//1. get the json string
string json = System.IO.File.ReadAllText("test.json");
//2. convert to JObject
var model = JObject.Parse(json);
//3. get userDetails json string
string jsonstring = model["userDetails"].ToString();
UserResponseDTO dto = new UserResponseDTO();
dto = JsonConvert.DeserializeObject<UserResponseDTO>(jsonstring);

Deserialize Json to C# object with array of arrays

Hello I have serious issues with populating my JSON file to C# object, because JSON contains "array of arrays of arrays". I need to create class with all the arrays to be able load the files there after deserialize, but i have no idea how to create structure like that.
JSON file:
{
"status": true,
"result": [
{
"ID": "1",
"UserID": "1001",
"web_id": "2753",
"certificate_id": "31",
"domain": "testsomething.com",
"status": "ssl_uninstalling",
"updated_at": "2017-02-15 15:08:04",
"IP": "xx.x.xxx.xxx",
"OS_version": "CentOS release 4.8"
},
{
"ID": "2",
"UserID": "1001",
"web_id": "2753",
"certificate_id": "31",
"domain": "admin.testsomething.com",
"status": "ssl_uninstalling",
"updated_at": "2017-02-13 14:19:45",
"IP": "xx.x.xxx.xxx",
"OS_version": "CentOS release 4.8"
},
{
"ID": "3",
"UserID": "1001",
"web_id": "2753",
"certificate_id": "31",
"domain": "www.testsomething16.com",
"status": "ssl_uninstalling",
"updated_at": "2017-02-16 16:22:40",
"IP": "xx.x.xxx.xxx",
"OS_version": "CentOS release 4.8"
},
{
"ID": "4",
"UserID": "1001",
"web_id": "2753",
"certificate_id": "31",
"domain": "blog.testsomething.com",
"status": "ssl_uninstalling",
"updated_at": "2017-02-16 16:22:40",
"IP": "xx.x.xxx.xxx",
"OS_version": "CentOS release 4.8"
}
],
"errors": []
}
The structure for your json might look like
public class Result
{
[JsonProperty("ID")]
public string ID { get; set; }
[JsonProperty("UserID")]
public string UserID { get; set; }
[JsonProperty("web_id")]
public string web_id { get; set; }
[JsonProperty("certificate_id")]
public string certificate_id { get; set; }
[JsonProperty("domain")]
public string domain { get; set; }
[JsonProperty("status")]
public string status { get; set; }
[JsonProperty("updated_at")]
public string updated_at { get; set; }
[JsonProperty("IP")]
public string IP { get; set; }
[JsonProperty("OS_version")]
public string OS_version { get; set; }
}
public class Rootobject
{
[JsonProperty("status")]
public bool status { get; set; }
[JsonProperty("result")]
public List<Result> result { get; set; }
[JsonProperty("errors")]
public List<object> errors { get; set; }
}
You can use Visual Studio to create classes for you out of JSON.
Copy your JSON in the clipboard. that means just CTRL + C and then go to Visual Studio Edit -> Paste Special -> Paste JSON As Classes
Another way out to create class sturcture for your JSON could be you can go to json2csharp: generate c# classes from json and create the classes.
I think you can create a model like below:
public class Example
{
public bool Status { get; set; }
public ResultModel ResultModel { get; set; }
public bool Error { get; set; }
public Example()
{
ResultModel = new ResultModel();
}
}
public class ResultModel
{
public int ID { get; set; }
public int UserId { get; set; }
public int WebId { get; set; }
}

C# Parse Json with multiple objects and arrays newtonsoft

I'm attempting to parse a rather convoluted/unnecessarily complicated JSON output using newtonsoft in C# however for some reason my parser always returns null. I have searched all over SO and cant't seem to find a solution.
An example of a JSON file I'm trying to parse:
{
"success": 1,
"d": {
"gameData": {
"MJ2Y7tDg": {
"scores": [
{
"max": 1.83,
"avg": 1.73,
"rest": 2,
"active": true,
"scoreid": "2c556xv464x0x4vtqc"
},
{
"max": 3.47,
"avg": 3.24,
"rest": 2,
"active": true,
"scoreid": "2c556xv498x0x0"
},
{
"max": 6.06,
"avg": 5.08,
"rest": 1,
"active": true,
"scoreid": "2c556xv464x0x4vtqd"
}
],
"count": 62,
"highlight": [
false,
true
]
},
"jZICYUQu": {
"scores": [
{
"max": 2.25,
"avg": 2.13,
"rest": null,
"active": true,
"scoreid": "2c5guxv464x0x4vuiv"
},
{
"max": 3.55,
"avg": 3.29,
"rest": null,
"active": true,
"scoreid": "2c5guxv498x0x0"
},
{
"max": 3.9,
"avg": 3.33,
"rest": null,
"active": true,
"scoreid": "2c5guxv464x0x4vuj0"
}
],
"count": 62,
"highlight": [
false,
false
]
}
}
}
}
This is what i have so far, I am very new to JSON wrangling :)
public class RootObject
{
public int success { get; set; }
public List<d> d { get; set; }
}
public class d
{
public List<gameData> gameData { get; set; }
}
public class gameData
{
public IDictionary<string, Score> gameData{ get; set; }
public List<scores[]> GameList;
}
public class Score
{
public double max { get; set; }
public double avg { get; set; }
public int rest { get; set; }
public bool active { get; set; }
public string scoreid { get; set; }
}
Anyone with more JSON wrangling experience know how to get this working?
Thankyou in advanced.
P.S I am currently in high school, learning C#
The parser returns null because structure of your classes doesn't correctly resemble the structure of JSON. The correct structure of classes would be:
public class RootObject
{
public int success { get; set; }
public Class_d d { get; set; }
}
public class Class_d
{
public Dictionary<string, GameData> gameData { get; set; }
}
public class GameData
{
public List<Score> scores { get; set; }
public int count { get; set; }
public bool[] highlight { get; set; }
}
public class Score
{
public decimal max { get; set; }
public decimal avg { get; set; }
public int? rest { get; set; }
public bool active { get; set; }
public string scoreid { get; set; }
}
and you can use it as follows:
string json = "..."; // the JSON in your example
RootObject root = JsonConvert.DeserializeObject<RootObject>(json);

What am I missing? RestSharp won't deserialize Json

I am trying to turn a json response back from foursquare into objects. I get something like this back
{
"meta":{
"code":200
},
"response":{
"venues":[
{
"id":"4abfb58ef964a520be9120e3",
"name":"Costco",
"contact":{
"phone":"6045967435",
"formattedPhone":"(604) 596-7435"
},
"location":{
"address":"7423 King George Hwy",
"crossStreet":"btw 76 Avenue & 73A Avenue",
"lat":49.138259617056015,
"lng":-122.84723281860352,
"distance":19000,
"postalCode":"V3W 5A8",
"city":"Surrey",
"state":"BC",
"country":"Canada",
"cc":"CA"
},
"canonicalUrl":"https:\/\/foursquare.com\/v\/costco\/4abfb58ef964a520be9120e3",
"categories":[
{
"id":"4bf58dd8d48988d1f6941735",
"name":"Department Store",
"pluralName":"Department Stores",
"shortName":"Department Store",
"icon":{
"prefix":"https:\/\/foursquare.com\/img\/categories_v2\/shops\/departmentstore_",
"suffix":".png"
},
"primary":true
}
],
"verified":true,
"restricted":true,
"stats":{
"checkinsCount":2038,
"usersCount":533,
"tipCount":12
},
"url":"http:\/\/www.costco.ca",
"specials":{
"count":0,
"items":[
]
},
"hereNow":{
"count":0,
"groups":[
]
},
"referralId":"v-1366316196"
}
]
}
}
I made a class like this
public class Response
{
public string Meta { get; set; }
public List<Venue> Venues { get; set; }
}
public class Venue
{
public string Id { get; set; }
public string Name { get; set; }
public Contact Contact { get; set; }
public Location Location { get; set; }
public string CanonicalUrl { get; set; }
public Categories Categories { get; set; }
public bool Verified { get; set; }
}
var response = client.Execute<Response>(request);
var test = response.Data;
Yet Venues is always null. I am not sure why though.
You simply need to go a level deeper in the JSON response. One level up from the venues property is the response property, which is not currently represented in your Response class.
You have two ways to solve this.
1) Add another wrapping response object, which contains the missing response property
// this is the new wrapping object
public class FourSquareResponse
{
public string Meta { get; set; }
public VenueResponse Response { get; set; } // previously missing
}
public class VenueResponse
{
public List<Venue> Venues { get; set; }
}
public class Venue
{
public string Id { get; set; }
public string Name { get; set; }
public Contact Contact { get; set; }
public Location Location { get; set; }
public string CanonicalUrl { get; set; }
public Categories Categories { get; set; }
public bool Verified { get; set; }
}
And executing the request...
var request = new RestRequest(uri);
var response = client.Execute<Response>(request);
2) Ignore the meta property and start parsing at the response property.
*As an aside, it looks like the meta property of the JSON response might be an HTTP status code. If it is and you still need it, RestSharp provides that for you as well (see below).
public class Response
{
public string Meta { get; set; }
public List<Venue> Venues { get; set; }
}
public class Venue
{
public string Id { get; set; }
public string Name { get; set; }
public Contact Contact { get; set; }
public Location Location { get; set; }
public string CanonicalUrl { get; set; }
public Categories Categories { get; set; }
public bool Verified { get; set; }
}
However, this will require telling RestSharp where to start parsing the response.
var request = new RestRequest(uri)
{
RootElement = "response"
};
var response = client.Execute<Response>(request);
// and the HTTP status (if that's what you need)
response.StatusCode
If i am going in right direction then, ur JSON is not Valid
Error:Strings should be wrapped in double quotes
Get it validated jsonformatter
[UPDATED]
Valid JSON would be like:-
{
"meta": {
"code": 200
},
"notifications":
[
{
"type": "notificationTray",
"item": {
"unreadCount": 0
}
}
],
"response": {
"venues": [
{
"id": "4e15d1348877cd5712112a44",
"name": "The Arena",
"contact": { },
"location": {
"address": "110 Wall Street",
"lat": 40.70432634495503,
"lng": -74.0055421062419,
"distance": 671,
"city": "New York",
"state": "NY",
"country": "United States",
"cc": "US"
},
"canonicalUrl": "https://foursquare.com/v/the-arena/4e15d1348877cd5712112a44",
"categories": [
{
"id": "4bf58dd8d48988d1e4941735",
"name": "Campground",
"pluralName": "Campgrounds",
"shortName": "Campground",
"icon": {
"prefix": "https://foursquare.com/img/categories_v2/parks_outdoors/campground_",
"suffix": ".png"
},
"primary": true
}
],
"verified": false,
"stats": {
"checkinsCount": 149,
"usersCount": 25,
"tipCount": 4
},
"specials": {
"count": 0,
"items": [ ]
},
"hereNow": {
"count": 0,
"groups": [ ]
},
"referralId": "v-1366314443"
}
]
}
}
JSON deserialization to .NET objects is case sensative. Your property names don't match the JSON tags properly, and that is why when you attempt to deserialize, you are getting back NULL.

Categories

Resources