Jeroen Everhard

Jeroen Everhard

  • NA
  • 111
  • 7.6k

Remove outer qoutes from JSON string

Oct 22 2020 7:23 AM
Hello,
 
I have a Controller in which I create a list and want to return this as JSON.
  1. public class ItemsController : ApiController  
  2. {  
  3.    public IHttpActionResult GetItems(ODataQueryOptions<App4Sales_Items> opts)  
  4.    {  
  5.       //Code for filling list ommited        
  6.       Dictionary<string, List<App4Sales_Items>> dic1 = new Dictionary<string, List<App4Sales_Items();  
  7.       dic1.Add("Results", result);        
  8.       JavaScriptSerializer js = new JavaScriptSerializer();  
  9.       var test = js.Serialize(dic1);  
  10.    
  11.      return Ok(test);  
  12.    }   
  13. }  
This returns the following JSON:
 
"{\"Results\":[{\"Id\":\"dc58d488-ab94-4c77-a11d-1cb135f7f2f4\"}]}"
 
But I would like:
 
{\"Results\":[{\"Id\":\"dc58d488-ab94-4c77-a11d-1cb135f7f2f4\"}]}, thus minus the most outer quotes.
 
How can I do that?
 
Jeroen

Answers (4)