Desserializatsiya dynamic array JSON in C # WebForm

Hi, I'm creating in my JSON API, which I'm trying to use C # Codebehind in your web application, but I can not deserialize well.

My JSON has an object with JSON arrays, and the element inside the array is dynamic, so I cannot create a fixed class with these elements, because my JSON can have N ITEMS.

{ "MAINOBJET": [{ "ITEM1": "23800", "ITEM2": "Dahl; Police", "ITEM3": " test@test.net " }, { "ITEM1": "23802", "ITEM2": "Steve ; Police", "ITEM3": " test2@test.net " }] } 

So, how can I deserialize it into a DataTable, list or dictionary? thank you

+4
source share
1 answer

here you can do something like the following to the example could help you replace .. structure / sample your text Jason

lets say my json script is as follows

 { "some_number": 253.541, "date_time": "2012-26-12T11:53:09Z", "serial_number": "SN8675309" "more_data": { "field1": 1.0 "field2": "hello JSON Deserializer" } } 

assign json jsonText to a variable and pass it to the next c # code

 using System.Web.Script.Serialization; var jsonSerialization = new JavaScriptSerializer(); var dictObj = jsonSerialization.Deserialize<Dictionary<string,dynamic>>(jsonText); Console.WriteLine(dictObj["some_number"]); //outputs 253.541 Console.WriteLine(dictObj["more_data"]["field2"]); //outputs hello JSON Deserializer ); using System.Web.Script.Serialization; var jsonSerialization = new JavaScriptSerializer(); var dictObj = jsonSerialization.Deserialize<Dictionary<string,dynamic>>(jsonText); Console.WriteLine(dictObj["some_number"]); //outputs 253.541 Console.WriteLine(dictObj["more_data"]["field2"]); //outputs hello JSON Deserializer 
+5
source

All Articles