Destroy a Json string (in C #) without Json.Net

I use the following lines to deserialize simple Json strings as follows:

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 using the Entity Framework.

The problem is that this method does not 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 Hobbie.

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

Thank,

Sincerely.

+3
source share
1 answer

.NET DataContractJsonSerializer? , , JavaScriptSerializer, .

+2

Source: https://habr.com/ru/post/1768186/


All Articles