Guest User

Untitled

a guest
Sep 9th, 2013
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. "location":{
  2. "address":"123 foo Street",
  3. "zip":"94102",
  4. "citycode":"usa:ca:sanfrancisco:downtown",
  5. "name":"San Francisco (Downtown)",
  6. "state":"CA",
  7. "country":"USA",
  8. "latitude":"37.7878",
  9. "longitude":"-122.4101"},
  10.  
  11. "location":[],
  12.  
  13. Cannot deserialize JSON array into type 'LocationData'
  14.  
  15. [JsonProperty(NullValueHandling = NullValueHandling.Ignore,Required=Required.AllowNull)]
  16. public LocationData location{get;set;}
  17. ...
  18. public class LocationData
  19. {
  20. public string zip { get; set; }
  21. public string address { get; set; }
  22. public string citycode { get; set; }
  23. public string name { get; set; }
  24. public string state { get; set; }
  25. public string country { get; set; }
  26. public decimal latitude { get; set; }
  27. public decimal longitude { get; set; }
  28. }
  29.  
  30. public class LocationDataConverter : JsonConverter
  31. {
  32. public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
  33. {
  34. if (reader.TokenType == JsonToken.StartArray)
  35. {
  36. reader.Read(); //move to end array
  37. return null;
  38. }
  39.  
  40. var data = new LocationData();
  41. serializer.Populate(reader, data);
  42.  
  43. return data;
  44. }
  45. }
  46.  
  47. [JsonConverter(typeof(LocationDataConverter))]
  48. public class LocationData {...}
Add Comment
Please, Sign In to add comment