JSON Deserializer to Class with property names that have periods

Hi:

I have the following JSON string that I am trying to deserialize:

{"cmi.core.lesson_status":"incomplete"}

I am trying to deserialize this in the following manner:

 
JavaScriptSerializer ser = new JavaScriptSerializer();
SCO sco = ser.Deserialize <SCO>(data_value);

Open in new window


My difficulty is making the SCO class:

When I go to create the class - i.e.

 
private string cmi.core.lesson_status;

public string Cmi.Core.LessonStatus
 {
     get { return cmi.core.lesson_status; }
     set { cmi.core.lesson_status = value; }
 }

Open in new window


I get an error telling me that there is no namespace core...

Any suggestions on how I could handle this greatly appreciated.

RBS
RBSAsked:
Who is Participating?
 
ddayx10Connect With a Mentor Commented:
Looks like your trying to create a class within a particular namespace. The syntax you are using is not going to compile (as you already know).

You'd want to do something like the following(see snippet).

You may want to do a search on c# namespace, or .net namespace to get a little more info.


namespace cmi.core
{
    public class SomeClass
    {
        //This would be common practice for a "property" in a class
        //c# conventions past 3.0 (I believe) make this part superfluous.
        private string lesson_status;

        //This is the actual property
        public string LessonStatus
        {
            get { return lesson_status; }
            set { lesson_status = value; }
        }

        //This would be a default constructor
        public SomeClass()
        { }
    }
}

Open in new window

0
 
ddayx10Commented:
PS: You likely also need to make the class "serializable"...

Info.... http://msdn.microsoft.com/en-us/library/system.serializableattribute%28v=VS.90%29.aspx

namespace cmi.core
{
    [Serializable()]
    public class SomeClass
    {
        //This would be common practice for a "property" in a class
        //c# conventions past 3.0 (I believe) make this part superfluous.
        private string lesson_status;

        //This is the actual property
        public string LessonStatus
        {
            get { return lesson_status; }
            set { lesson_status = value; }
        }

        //This would be a default constructor
        public SomeClass()
        { }
    }
}
0
 
ddayx10Commented:
Just for the heck of it I'll throw this out there, you could simplify your property creation by doing the following. In c# 3.0 and higher the convention has been simplified due to common practice.

<see snippet>
namespace cmi.core
{
    [Serializable()] 
    public class SCO
    {
        //This would be common practice for a "property" in a class
        //c# conventions past 3.0 (I believe) make this part superfluous.
        //private string lesson_status;

        //This is the actual property
        public string LessonStatus
        {
            get;
            set;
        }

        //This would be a default constructor
        public SCO()
        { }
    }
}

Open in new window

0
 
RBSAuthor Commented:
thanks!

rbs
0
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.

All Courses

From novice to tech pro — start learning today.