Search code examples
c#vmc

Parse JSON String into List C# VMC


Dear all my brother i have this Json Data enter image description here

0: Object { no: "1", project: "Rosato", job_type: "គ្រឿងសង្ហារឹម", … }
1: Object { no: "2", project: "KPS", job_type: "គ្រឿងសង្ហារឹម", … }

i want to extract it in to c# List or data table please help!


Solution

  • Add Newtonsoft.Json as a reference in your project

    string myJsonString = MyMethodToReadJsonAsStringFromDataSource(dataSourceConnection);
    IEnumerable<dynamic> myObjects = JsonConvert.DeserializeObject<dynamic>(myJsonString);
    foreach(dynamic myObject in myObjects)
    {
         // access to your abject
         string no = myObject.no;
         string project = myObject.project;
         string job_type = myObject.job_type;
    }
    

    You can replace dynamic with a class you create that maps to your json object so you can have full access to your object at compiler time.