-3

i Have table that may contains null values in rows that may lead to null at client side.. so i want empty in place of null..

if i send Json String it give double quotes around string.. but i Wanna treat this is json object..

like this

"[  
   {  
      "BusinessEntityID":274,
      "TerritoryID":"",
      "SalesQuota":"",
      "Bonus":0.0000,
      "CommissionPct":0.0000,
      "SalesYTD":559697.5639,
      "SalesLastYear":0.0000,
      "rowguid":"48754992-9ee0-4c0e-8c94-9451604e3e02",
      "ModifiedDate":"2005-01-28T00:00:00"
   },
   {  
      "BusinessEntityID":275,
      "TerritoryID":2,
      "SalesQuota":300000.0000,
      "Bonus":4100.0000,
      "CommissionPct":0.0120,
      "SalesYTD":3763178.1787,
      "SalesLastYear":1750406.4785,
      "rowguid":"1e0a7274-3064-4f58-88ee-4c6586c87169",
      "ModifiedDate":"2005-06-24T00:00:00"
   }
]"

but i wanna treat this is json object while sending string to response

 DataTable dt = (new tst()).Gettable();
            string s = string.Empty;
            s = Newtonsoft.Json.JsonConvert.SerializeObject(dt);
            return Ok(s);

if i return s then output at client side treated as string. and if i return dt then it show null for empty cells.

but i wanna replace null with "" without making string. Please dont give silly answsers..To the Point.
Having Problem in understanding question ..then you can ask

I have solve this by making overhead to code by here

Community
  • 1
  • 1
rakeshyadvanshi
  • 294
  • 3
  • 9
  • _"it give double quotes around string"_ - that's the debugger. – CodeCaster Mar 02 '16 at 19:15
  • this is not debugger @CodeCaster but this is output at client side – rakeshyadvanshi Mar 02 '16 at 19:17
  • Could you give us some more information on the problem? It sound like it may help you to take a look at the answers to [this question](http://stackoverflow.com/questions/6620165/how-can-i-parse-json-with-c) on serializing JSON objects. – Scott Ferguson Mar 02 '16 at 19:18

1 Answers1

2

You're telling Web API to serialize a string as JSON.
It therefore dutifully escapes the string.

You should pass the raw object to Ok() and let Web API serialize it for you.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964