Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6792885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:01:47+00:00 2026-05-26T18:01:47+00:00

I am trying to parse out data from oodle.com api feed using the JSON.NET

  • 0

I am trying to parse out data from oodle.com api feed using the JSON.NET lib. Part of the response JSON string to deserialize has the following ‘location’ structure:

"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"},

however I’ve seen instances of location declared as an empty array:

"location":[],

I am trying to deserialize it in a class of type Location Data. This works perfect when location has valid data in it but it does not work well when the location is represented as an empty array. I tried adding the attributes (NullValueHandling & Required) to have set the location instance as null if the data is indeed an empty array but I think these attribs are meant for serialization only. If the array is empty I get an exception

Cannot deserialize JSON array into type 'LocationData'

Is there a way to tell the deserializer to not complain and make the location object null if the array the deserialization fails?
Thanks!

[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; }
     }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:01:48+00:00Added an answer on May 26, 2026 at 6:01 pm

    You can write a custom converter for the LocationData type to turn array tokens in to null.

    Something like:

    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;
            }
    }
    

    Then just tag the LocationData class:

    [JsonConverter(typeof(LocationDataConverter))]
    public class LocationData {...}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse some JSON data from the Google AJAX Search API. I
I am trying to parse out some information from Google's geocoding API but I
I'm trying to parse some data out of a file using Perl & Parse::RecDescent.
Greetings, I am trying to parse live weather data from Weatherbug's RSS feed in
I'm trying to parse out some data thats returned from a web service via
I'm trying to parse a single string and get multiple chunks of data out
I'm trying to parse data from Archive.org's search functionality. The data looks like this:
Hi I am trying to parse data out of an XML file I exported
I am trying to parse some data from external site to local script. Local
I'm trying to parse JSON string using Boost Spirit store JSON object into recursive

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.