Deserialization Blues


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.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RBSAuthor Commented:
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?

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.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.