c# - How to output Json string as JsonResult in MVC4? -
this seems simple must over-thinking it.
tl;dr;
how can modify code below return json object contained in string rather string happens contain json?
public actionresult test() { var json_string = "{ success: \"true\" }"; return json(json_string, jsonrequestbehavior.allowget); }
this code returns string literal containing json:
"{ success: "true" }"
however, i'd return json contained in string:
{ success: "true" }
slightly longer version
i'm trying prototype external api calls , want pass results through "api" fake response now. json object non-trivial - on order of 10,000 "lines" or 90kb. don't want make typed object(s) contents of 1 json response can run through deserializer - out.
so basic logic in controller is:
- call externall api
- store string result of web request var (see json_string above)
- output results json (not string) using jsonresult producing method json()
any appreciated... mind melting.
the whole point of json()
helper method serialize json.
if want return raw content, directly:
return content(jsonstring, "application/json");
Comments
Post a Comment