2

I am using c# and i have a DataSet (ds) with 2 Datatables (dt1,dt2) having relations to each other. Now i want to convert the Dataset to a nested json string.

Option1:

string myresult = JsonConvert.SerializeObject(ds);

Using this creates a non-nested json string. Result: Displays all values from dt1 first, then all values from dt2

Option:2:

string myresult = ds.GetXml();
XmlDocument doc = new XmlDocument();
doc.LoadXml(myresult);
return (JsonConvert.SerializeXmlNode(doc));

When i use this i get a nested json string but int-values are displayed as string-values ("Id": 1 is displayed as "Id": "1")

I think Convert Dataset with Relation to JSON string is a similar issue - the answer creates the same result like option 2

Community
  • 1
  • 1
Schauby
  • 172
  • 2
  • 16

1 Answers1

0

You might wanna look into this one

System.web.script.serialization.JavaScriptSerializer

https://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer(v=vs.110).aspx

Erk
  • 49
  • 1
  • Using this creates an error: {"A circular reference was detected while serializing an object of type 'System.Globalization.CultureInfo'."} and ignoring referenceloop creates option 1 output – Schauby Mar 03 '17 at 06:34