我错过了什么?RestSharp不会反序列化Json

cho*_*bo2 9 c# json foursquare restsharp

我试图将json响应从foursquare变回对象.我得到这样的东西了

   {
   "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"
         }
      ]
   }
}
Run Code Online (Sandbox Code Playgroud)

我做了这样一堂课

 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;
Run Code Online (Sandbox Code Playgroud)

Venues总是空的.我不知道为什么.

cho*_*bo2 19

好的,我找到了这个将json转换为对象的好工具http://json2csharp.com/.我发现通过这个我需要一个包装来使它工作.

  • 或者在Visual Studio中,您可以单击"编辑 - >粘贴特殊 - >作为Json",它会为您完成 (13认同)

Shu*_*ubh 0

如果我朝着正确的方向前进,那么你的 JSON 就不是Valid

Error:Strings should be wrapped in double quotes
Run Code Online (Sandbox Code Playgroud)

获取经过验证的jsonformatter

[更新]

有效的 JSON 类似于:-

{
"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"
}         
]
}

}
Run Code Online (Sandbox Code Playgroud)