[英]How can I send a json string to view as a json object?
我在MVC控制器的動作中有一個json字符串。 我想將其發送為JSON對象進行查看。 我該如何解決?
public JsonResult Json()
{
... some code here ...
string jsonString = "{\"Success\":true, \"Msg\":null}";
// what should I do instead of assigning jsonString to Data.
return new JsonResult() { Data = jsonString, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
public ActionResult Json()
{
... some code here ...
string jsonString = "{\"Success\":true, \"Msg\":null}";
return Content(jsonString, "application/json");
}
但我建議您使用對象而不是字符串:
public ActionResult Json()
{
... some code here ...
return Json(
new
{
Success = true,
Msg = (string)null
},
JsonRequestBehavior.AllowGet
);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.