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 7409489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:05:25+00:00 2026-05-29T06:05:25+00:00

I’m working with an external REST API that returns some data as a comma-separated

  • 0

I’m working with an external REST API that returns some data as a comma-separated string of integers. I’ve been using Json.NET to deserialize the data I get into POCO. I added an int[] property to my class and wrote a custom converter to parse the comma separated string in to an int array. When I run my code, though I get an error that

“JsonConverter CellControlSpeedConverter on Int32[] Observations is not compatible with member type Int32[]”

Here’s my member declaration:

[JsonProperty(PropertyName = "speed-list")]
[JsonConverter(typeof(CellControlSpeedConverter))]
int[] Observations { get; set; }

Here’s my JsonConverter ReadJson: (omitted other methods for brevity, please ignore the overly pedantic syntax, was trying anything to get this working)

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{

        if (reader.TokenType == JsonToken.String)
        {
            throw new ArgumentException(String.Format("Unexpected token parsing speed observations. Expected String, got {0}.", reader.TokenType));
        }

        string delimitedObservations = reader.Value.ToString().Trim();
        char[] delimiter = new char[1] { ',' };
        string[] observations = delimitedObservations.Split(delimiter, StringSplitOptions.RemoveEmptyEntries);

        int[] output = new int[observations.Length];

        for (int sequence = 1; sequence <= observations.Length; sequence++)
        {
            string observation = observations[sequence - 1];
            int speed = 0;
            if (int.TryParse(observation, out speed))
            {
                output[sequence - 1] = speed;
            }
            else
            {
                throw new ArgumentException(String.Format("Unexpected speed value parsing speed observations. Expected Int, got {0}", observation));
            }
        }


        return output;

    }

I’ve tried some other member types like List<int> and Dictionary<int,int> with the same result. (the previous effort with the dictionary is why the loop iterator starts at 1)

  • 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-29T06:05:25+00:00Added an answer on May 29, 2026 at 6:05 am

    OK, I figured out my own problem after I installed the Json.NET source code and stepped through it.

    The issue was that the class that inherits from JsonConverter (in my case CellControlSpeedConverter) must implement a method called CanConvert that tells the Json Serializer whether or not your custom converter can perform the requested conversion. The input variable is Type objectType. The documentation is silent on what the purpose of this variable is.

    I had assumed (based mostly on the method name) that this variable represented the type of the INPUT object (that is, the source object that you are trying to convert FROM). It turns out that this method is actually passed the DESTINATION object type.

    So in my example above, my CanConvert method was returning true if passed a string and false otherwise. To get the conversion working I changed that method so that it returned true when passed int[] instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.