1

I have a very simple datatable which I serialize into JSON using Newtonsoft

DataTable dt = DBHelper.GetDataTable(value.Sql);
string json = JsonConvert.SerializeObject(dt, Formatting.None);
return json;

This is the result

"[{\"IdUsuario\":\"37\",\"IdEmpresa\":\"3\",\"Usuario\":\"koala\",\"NombreUsuario\":\"\",\"IdTercero\":\"715\",\"nit\":\"71790599\",\"Bloqueado\":\"0\",\"Descripcion\":\"\",\"IdDependencia\":\"\",\"IdBodega\":\"5\"}]"

I don´t know why i have extra "\" inside the field names, this only happens in this project (WebApi). If i do the same thing from a windows forms test application i have "normal" json.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Almost certainly because you are double-serializing your JSON as described in [JSON.NET Parser *seems* to be double serializing my objects](https://stackoverflow.com/q/25559179/3744182). – dbc Feb 12 '18 at 23:56
  • That was exactly the case, returning directly a datatable made the serialization. Thanks – Leonardo Perez Feb 13 '18 at 15:35

1 Answers1

0

You should convert your string as JSON-String:

string jsonConverted = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
Sean Stayns
  • 4,082
  • 5
  • 25
  • 35