Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "location":{
- "address":"123 foo Street",
- "zip":"94102",
- "citycode":"usa:ca:sanfrancisco:downtown",
- "name":"San Francisco (Downtown)",
- "state":"CA",
- "country":"USA",
- "latitude":"37.7878",
- "longitude":"-122.4101"},
- "location":[],
- Cannot deserialize JSON array into type 'LocationData'
- [JsonProperty(NullValueHandling = NullValueHandling.Ignore,Required=Required.AllowNull)]
- public LocationData location{get;set;}
- ...
- public class LocationData
- {
- public string zip { get; set; }
- public string address { get; set; }
- public string citycode { get; set; }
- public string name { get; set; }
- public string state { get; set; }
- public string country { get; set; }
- public decimal latitude { get; set; }
- public decimal longitude { get; set; }
- }
- public class LocationDataConverter : JsonConverter
- {
- public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
- {
- if (reader.TokenType == JsonToken.StartArray)
- {
- reader.Read(); //move to end array
- return null;
- }
- var data = new LocationData();
- serializer.Populate(reader, data);
- return data;
- }
- }
- [JsonConverter(typeof(LocationDataConverter))]
- public class LocationData {...}
Add Comment
Please, Sign In to add comment