JsonConvert.SerializeObject(datatable) is adding decimals

Here is the data that’s in my datatable:

[FIELDNAME,FIELDNUMBER,FIELDSTART,FIELDEND,DEFAULTVALUE
Account Number,0,0,0,22000xxxxxx9
Amount,3,0,0,
Void Check,0,0,0,
Check Number,1,0,0,
Payee Name,4,0,0,
Check Date,2,0,0,
]

Then I serialize it with this expression:

Newtonsoft.Json.JsonConvert.SerializeObject(DT_Fields)

Here is the result:

[{""FIELDNAME"":""Account Number"",""FIELDNUMBER"":0.0,""FIELDSTART"":0.0,""FIELDEND"":0.0,""DEFAULTVALUE"":22000xxxxxx9.0},{""FIELDNAME"":""Amount"",""FIELDNUMBER"":3.0,""FIELDSTART"":0.0,""FIELDEND"":0.0,""DEFAULTVALUE"":null},{""FIELDNAME"":""Void Check"",""FIELDNUMBER"":0.0,""FIELDSTART"":0.0,""FIELDEND"":0.0,""DEFAULTVALUE"":null},{""FIELDNAME"":""Check Number"",""FIELDNUMBER"":1.0,""FIELDSTART"":0.0,""FIELDEND"":0.0,""DEFAULTVALUE"":null},{""FIELDNAME"":""Payee Name"",""FIELDNUMBER"":4.0,""FIELDSTART"":0.0,""FIELDEND"":0.0,""DEFAULTVALUE"":null},{""FIELDNAME"":""Check Date"",""FIELDNUMBER"":2.0,""FIELDSTART"":0.0,""FIELDEND"":0.0,""DEFAULTVALUE"":null}]

How can I stop JsonConvert.SerializeObject from adding the decimal places to the numbers?

@postwick

You have to convert the datacolumn type to string for that to happen

Cheers

Quick Guess:
grafik
Data Column DataType is triggering the behaviour

A first look at the newtonsoft docu

did not offered a quick hint on finetuning the format handling

All the datatable columns are system.object thanks to the Excel activities having no way to force string. So in the end I just write it to CSV then read it back in so I can get the columns to be string, and now the seralize leaves the values alone.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.