[SOLVED] Parse Json String Without using newtonsoft


I encountered an issue which is I want to get the data from innermost json. Eg, I input Swimming then I will get student_ID : 0001 and Name : Jack. Something like this but I don’t want to use Newtonsoft or any other dll. My current code is shown below, I able to get data for the outmost which is Name and Birthday but not embedded. My code and json are below

    public class Hobby
        public string Sport { get; set; }
        public string Arcade { get; set; }

    public class OtherInfo
        public string student_ID { get; set; }
        public string Batch { get; set; }
        public Hobby Hobby { get; set; }

    public class Embedded
        public List<OtherInfo> OtherInfo { get; set; }

    public class Root
        public string Name { get; set; }
        public string birthday { get; set; }
        public Embedded embedded { get; set; }

var jsonObj = new JavaScriptSerializer().Deserialize<Root>(ApiCreateJsonData);
string testtsett = "";
foreach (var item in jsonObj.Name)
    testtsett += item.ToString();   
Label1.Text = testtsett;


It is as simple as:

foreach (var item in jsonObj.embedded.OtherInfo)
  testtsett += item.student_ID;
  testtsett += item.Hobby.Arcade;
  testtsett += item.Hobby.Sport;
  testtsett += item.Batch;

You need to loop over your List<OtherInfo> to get your embedded values:

Answered By – Rahul Sharma

Answer Checked By – Marie Seifert (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *