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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:32:40+00:00 2026-06-02T18:32:40+00:00

I am dealing with a REST-service that, depending on the information given to it

  • 0

I am dealing with a REST-service that, depending on the information given to it (it’s a search service), gives back elements with either string elements or a list of string elements. An example could be searching for an item that has zero or more images – saved as url-strings. My model contains the following property to deal with my example:

private List<string> _Images = new List<string>();
[DataMember(Name="images", IsRequired=false)]
public List<string> Images
{
    get
    {
        return _Images;
    }
    set
    {
        _Images = value;
        onPropertyChanged("Images");
    }
}

Sample JSON with several images:

{
    "id": 24955,
    "title": "Conan the Barbarian",
    "duration": 105,
    "hd": false,
    "trailer": "800/BM_6305_800_tr.wmv",
    "images": [
        "http://website.com/images/conanthebar_1.jpg",
        "http://website.com/images/conanthebar_2.jpg",
        "http://website.com/images/conanthebar_3.jpg",
        "http://website.com/images/conanthebar_4.jpg",
        "http://website.com/images/conanthebar_5.jpg",
        "http://website.com/images/conanthebar_6.jpg"
    ]
}

Sample JSON with ONE image:

{
    "id": 24955,
    "title": "Conan the Barbarian",
    "duration": 105,
    "hd": false,
    "trailer": "800/BM_6305_800_tr.wmv",
    "images": "http://website.com/images/conanthebar_6.jpg"
}

Now, my question is, when I’m using DataContractJsonSerializer, how will this be handled? If the image string of my incoming json is a single string (compared to an array / list of strings), will it convert it to a list of strings with only one member?


Finally, if this ISN’T the case (my theory is false), how could such a situation be handled?

  • 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-06-02T18:32:42+00:00Added an answer on June 2, 2026 at 6:32 pm

    Kris, if DataContractJsonSerializer is expecting an array or any IEnumerable of strings, it will actually expect something in the following format:

    [ “str1”, “str2”, “str3”, …]

    If it receives only a string, like below:

    “str1”

    it will actually throw an exception. It does not automatically convert this to an array, and there is no way to.

    One workaround you have, however, is if you declare “Images” to be of type System.Object. If you do this, serialization will work the same. Deserialization will work exactly how you want it — it will deserialize to an array of strings if encounters an array, and it will deserialize to a System.string if it encounters a string.

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

Sidebar

Related Questions

I have successfully set up a quick test of creating a REST-like service that
I'm dealing with some legacy code that stores its data in a proprietary string
I am dealing with very primitive HTML construction that goes like this: <a NAME=header1></a><b><font
I've been dealing with a legacy asp.net 2.0 web site that was originally setup
I am working through a REST services book dealing with WCF. I have been
We are creating an API that suits the benefits of a REST based architecture.
Say your calling a REST service from your javascript code in the browser. Your
Basically, I'm dealing with a horribly set up table that I'd love to rebuild,
I'm using MVC for REST so that I can take advantage of Razor for
I am writing some code to interface with a service that I do not

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.