0

I have an Json string with Multiple Json Object.I would like to know how to deserialize Json string to DataSet

I have deserialize Json string to DataTable.It works fine but I would like to know how to convert multiple json object to dataset

 public static DataTable JsonToDataTable(string StrController)
    {
        DataTable Table = new DataTable();
        using (var httpClient1 = new HttpClient())
        {
            httpClient1.BaseAddress = new Uri("http://laravel.kharind.com:90/");
            httpClient1.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            HttpResponseMessage response = httpClient1.GetAsync("api/"+StrController).Result;
            if (response.IsSuccessStatusCode)
            {
                var message = response.Content.ReadAsStringAsync().Result;
                Table = (DataTable)JsonConvert.DeserializeObject(message,(typeof(DataTable)));
            }
        }
        return Table;
    }

Json string :-

{
   "Header":[
      {
         "GatePassHeaderId":"15683",
         "GatePassNo":"LI/19/0074",
         "GatePassDate":"2019-10-10 00:00:00",
         "GatePassType":null,
         "ToName":"Hoggo Boss",
         "SupplierId":"397",
         "PreparedBy":"Anwarullah",
         "AuthorizedBy":"Asraar Ahmed",
         "ReceivedBy":"By Van",
         "DespatchMode":"Blue Dart Courier",
         "VehicleNo":"TN-20 CW 9420",
         "Value":null,
         "Remarks":"test",
         "Remarks2":"4",
         "IsReturnable":"1",
         "ReceivedInGate":"0",
         "Closed":null,
         "PrintTime":null,
         "AirwayBillNo":null,
         "Approved":null,
         "WithoutApproved":null,
         "CreatedUserId":"0",
         "CreatedDateTime":"2019-10-10 09:47:00",
         "SystemUserId":"ismail",
         "LastModifiedUserId":null,
         "LastModifiedDateTime":null
      }
   ],
   "Details":[
      {
         "JobWorkDetailsId":"32",
         "MaterialId":"13476",
         "Quantity":"44.00",
         "CGST":"5.00",
         "SGST":"5.00",
         "IGST":"5.00",
         "Rate":"56.00"
      },
      {
         "JobWorkDetailsId":"33",
         "MaterialId":"13519",
         "Quantity":"55.00",
         "CGST":"7.00",
         "SGST":"7.00",
         "IGST":"7.00",
         "Rate":"67.00"
      }
   ]
}
Jimi
  • 29,621
  • 8
  • 43
  • 61
Muhammed Ismail
  • 125
  • 2
  • 12
  • 2
    `var dataset = JsonConvert.DeserializeObject(Json);` You'll get a DataSet with 2 DataTables. – Jimi Oct 10 '19 at 07:45

1 Answers1

0

Pretty good answers here: Convert JSON to DataTable . If you have multiple responses (arrays) you can make an for for each / iterate each one.

StefanaB
  • 184
  • 2
  • 11