Rameez Javed

Rameez Javed

  • NA
  • 395
  • 61.5k

Converting Dataset to Json with Empty datatable's columns

Dec 7 2020 11:03 PM
Hi everyone, I want to convert DataSet to Json using newtonsoft. I converted it successfully but an issue here is the datatable with 0 rows are column less in json.
 
I'm getting the json like below, but I want to have dt_3 with its columns names.
 
What I'm doing is 
  1. string json_withoutStoreDetails = JsonConvert.SerializeObject(dset, Newtonsoft.Json.Formatting.Indented);
  1. {  
  2.   "dt_1": [  
  3.     {  
  4.       "depid": 51.0,  
  5.       "DepName""Honda",  
  6.       "Amount": 110.50  
  7.     },  
  8.     {  
  9.       "depid": 54.0,  
  10.       "DepName""Toyota",  
  11.       "Amount": 100.60  
  12.     },  
  13.     {  
  14.       "depid": 56.0,  
  15.       "DepName""Diahatsu",  
  16.       "Amount": 120.00  
  17.     },  
  18.     {  
  19.       "depid": 57.0,  
  20.       "DepName""Bedford",  
  21.       "Amount": 380.00  
  22.     },  
  23.   ],  
  24.   "dt_2": [  
  25.     {  
  26.       "depid": 50,  
  27.       "DepName""AlloyRims",  
  28.       "Amount": 21.50  
  29.     }  
  30.   ],  
  31.   "dt_3": [  
  32.       
  33.   ],  
  34. }  


Answers (3)