This seems so simple I must be over-thinking it.
TL;DR;
How can I modify the code below to return the json object contained in the string rather than a string that happens to contain json?
public ActionResult Test() { var json_string = "{ success: \"true\" }"; return Json(json_string, JsonRequestBehavior.AllowGet); }
This code returns a string literal containing the json:
"{ success: "true" }"
However, I'd like it to return the json contained in the string:
{ success: "true" }
Slightly longer version
I'm trying to quickly prototype some external api calls and just want to pass those results through my "api" as a fake response for now. The json object is non-trivial - something on the order of 10,000 "lines" or 90KB. I don't want to make a strongly typed object(s) for all the contents of this one json response just so I can run it through a deserializer - so that is out.
So the basic logic in my controller is:
Any help is greatly appreciated... mind is melting.
The ActionResult is defined in the controller and the controller returns to the client (the browser). What is JsonResult ? JsonResult is one of the type of MVC action result type which returns the data back to the view or the browser in the form of JSON (JavaScript Object notation format).
JSON you are returning contains 4 properties, the way you are accessing isValid , similarly access the View . $. ajax({ type: "GET", url: "/serviceentry/getservice", data: ({ "SONumber": soNumber }), success: function (data) { if (data. isValid) { //Element- Where you want to show the partialView $(Element).
The whole point of the Json()
helper method is to serialize as JSON.
If you want to return raw content, do that directly:
return Content(jsonString, "application/json");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With