Click here to Skip to main content
14,775,221 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do you serialize and deserialize without Newtonsoft? This is my attempt at it.
var serializer = new JavaScriptSerializer();
var json1 = "[count:{first:1,second:2,third:3},{first:11,second:22,third:33},{first:111,second:222,third:333}]";
var jsons = serializer.Serialize(json1);
dynamic jsona = serializer.Deserialize(json1, typeof(object));

Second Part: how to extract the data:

for each (jsone in jsona)

What I have tried:

Tried installing Newtonsoft. Unsucessful.

This simple Javasciptserilizer is not working either but it is the best and simplest i have found.
Updated 28-Mar-17 20:21pm

1 solution

the above is not a valid json format, it should be
var json1 = "{count:[{first:1,second:2,third:3},{first:11,second:22,third:33},{first:111,second:222,third:333}]}";

and deserialized as
public class MyClass
          public Number[] count { get; set; }

      public class Number
          public int first { get; set; }
          public int second { get; set; }
          public int third { get; set; }

      static void Main()

          var serializer = new JavaScriptSerializer();
          var json1 = "{count:[{first:1,second:2,third:3},{first:11,second:22,third:33},{first:111,second:222,third:333}]}";
          MyClass jsona = (MyClass)serializer.Deserialize(json1, typeof(MyClass));
          foreach (Number item in jsona.count)
              var first = item.first;
              var second = item.second;
              var third = item.third;


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900