What am I missing? RestSharp won't deserialize Json What am I missing? RestSharp won't deserialize Json json json

What am I missing? RestSharp won't deserialize Json


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 objectpublic 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.