3

I use the following lines to deserialize simple Json strings like this:

string jSon = "{\"FirstName\":\"Foo\", \"LastName\":\"Bar\"}";
System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
Person personDeserialized = oSerializer.Deserialize<Person>(jSon);

Then, I add the "personDeserialized" object to the database with Entity Framework.

The problem is that this method doesn't work if I have the following data :

string jSon = "{
   \"FirstName\":\"Foo\", 
   \"LastName\":\"Bar\",
   \"Hobbies\":
   [
      {\"Sport\":\"FootBall\"},
      {\"Music\":\"Rock\"},
   ]
}";

Of course, the Person class contains references to the Hobbie's one.

So, is there a way, and without the jSon.NET library, to add the "Hobbies" object automatically to the personDeserialized object?

Thanks,

Regards.

1 Answer 1

2

Have you tried using the new .NET DataContractJsonSerializer? I believe I works much better than the JavaScriptSerializer that you're using.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.