A function in ASP.NET Web Api is returning a simple string as JSON data.
However, when calling this function from AngularJS, the returned value is surrounded by quotes instead of being a plain string:
return $http.post('/api/orders', data).then(function (results) {
return result.data;
The value of result.data appears as "my string"
, enclosed in quotes. This is because the response is a string primitive and not an object. What is the recommended approach to handle this issue? Should we remove the quotes using a JavaScript function? Or should we modify the server to return an object instead of a primitive? Are there any specific configurations that need to be tweaked?
UPDATE:
The server utilizes a Web Api controller that directly returns a string:
public IHttpActionResult SaveOrder() {return Ok("this is a test");}
This has the same effect as:
public string SaveOrder() {return "this is a test";}
The problem here is that the JSON value returned is not structured as an object; it's simply the raw string primitive.