-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

3
  • "it give double quotes around string" - that's the debugger. Commented Mar 2, 2016 at 19:15
  • this is not debugger @CodeCaster but this is output at client side Commented Mar 2, 2016 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 on serializing JSON objects. Commented Mar 2, 2016 at 19:18

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Happy 500K, SLaks. Edit: oh, that'll be tomorrow. :P
You haven't understand problem..please go thorough again
If you want to replace nulls, you should do that in the table, not in the JSON string.
But This lead to extra overhead to process 45 columns and with 1000 rowss..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.