Deserialization Blues

Posted on 2011-10-21
Last Modified: 2012-05-12

I have a JSON string that I am trying to deserialize into an object that I have in a Web Service.

The string comes into my services as parameter string data_value and looks like this:


I have created a class called SCO that looks like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for SCO2
/// </summary>
namespace cmi.core
    public class SCO2
        public SCO2()

        private string lesson_status;
        private string total_time;

        public string Lesson_status
            get { return lesson_status; }
            set { lesson_status = value; }

        public string Total_time  //(
            get { return total_time; }
            set { total_time = value; }


Open in new window

In my Web Service, I attempt to deserialize the JSON string as follows:

JavaScriptSerializer ser = new JavaScriptSerializer();
        int lesson_status = 0;
            SCO sco  = ser.Deserialize<SCO>(Data_Value);

        catch (Exception er)
            string ErrorMessage = er.Message;

Open in new window

The procedure works fine except that the name value pairs in the JSON string don't match the class properties that I have created.
The problem is that in the name value pairs in the JSON string, the names have periods in them i.e.  cmi.core.something....

I've tried various methods by changing the namespace etc. in the class but to no avail.

Finally, I thought that I would take out the periods in the JSON string with:  string Data_Value = data_value.Replace("cmi.core.", "Cmi_core_");

That recults in a string Data_Value that looks like this:


It's exactly the same as the original string with underscores instead of periods.

However, when I use Data_Value as an input instead of data_value, I get the error message:

"Type 'System.String' is not supported for deserialization of an array."

I'm not sure what to do at this point.  Any suggestions greatly appreciated.


Question by:RBS

    Author Comment

    OK - so I figured it out - changed the elements in the class from

    public string Total_time  //(
                get { return total_time; }
                set { total_time = value; }

    public string Total_time  { get; set; }

    Why this worked, I have no idea?  Can any one suggest why?


    Accepted Solution

    Because you have presented a solution to your own problem which may be helpful to future searches, this question is now PAQed and your points have been refunded.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    This video discusses moving either the default database or any database to a new volume.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now