Hi All,
I am using CloudMade Api for using maps. This Api is returning Json result as Below:
{"places":[{"addressType":"street","city":"~Slough","country":"United Kingdom","featureType":"Ortsstrasse","position":{"lat":51.51465939,"lon":-0.58932440},"state":"England","street":"Adrians Walk","zip":"SL2 5AT"},{"addressType":"sight","city":"~Slough","country":"United Kingdom","featureType":"Building a terrain of interest","name":"Slough","position":{"lat":51.51206867,"lon":-0.59121503},"state":"England","street":"Railway Terrace"},{"addressType":"sight","city":"~Slough","country":"United Kingdom","featureType":"Station","name":"Slough","position":{"lat":51.51225777,"lon":-0.59193386},"state":"England","street":"Railway Terrace"}],"status":{"duration":636,"procedure":"geo.location.search.2","success":true}}
I want to de-serialize this response into object. I am currently using following object.
but it is throwing error "Cannot deserialize JSON object into type 'OpenstreetMap.places[]'."
public class places
{
public string addressType { get; set; }
public string city { get; set; }
public string country { get; set; }
public string featureType { get; set; }
public List<object> position { get; set; }
public string state { get; set; }
public string street { get; set; }
public string zip { get; set; }
public List<object> status { get; set; }
}
And I am using below code for this:
string s =@"http://beta.geocoding.cloudmade.com/v3/0552b29114ef41a4ac10d06bf97939b4/api/geo.location.search.2?format=json&source=OSM&enc=UTF-8&limit=10&locale=en&q=24%20adrians%20walk,%20slough";
var client = new RestClient(s);
var request = new RestRequest(s);
RestResponse response = client.Execute(request) as RestResponse;
var json = response.Content; // raw content as string
places[] obj = JsonConvert.DeserializeObject<places[]>(json);
Thanks
Umesh Tayade