I am using .NET C# MVC/API project. Inside a Controller I have the following code:
[HttpGet]
public ActionResult ArcGISinit()
{
var jsonString = "[{ 'number': '555', 'api': '777', 'text': 'text'}]";
return Json(jsonString, JsonRequestBehavior.AllowGet);
}
Then in my script file, I am able to get the above data like this:
// Path to the above **Controller**
var serviceURL = "...";
var respOriginal = [{ "number": 555, "api": "777", "text": text }];
$.ajax({
type: "GET",
url: serviceURL,
contentType: "application/json;",
dataType: "json",
success: successFunc,
error: errorFunc
});
function successFunc(data, status) {
// Probably don't need this
resp = JSON.stringify(data);
console.log("data:");
console.log(data);
console.log("respOriginal:");
console.log(respOriginal);
}
function errorFunc() {
alert('MVC controller call failed.');
}
Here is a thing when I look at it Chrome debugger, in data which is from MVC Controller I get this (a plain string):
[{ 'number': '555', 'api': '777', 'text': 'text'}]
but for respOriginal which is inside a script file, I get this
[Object]
When Object is expanded (data in respOriginal) looks properly formatted, like so:
number : 555
api : 777
text : "text"
How can I make data that comes from MVC Controller look like data in respOriginal ?