2010-06-17 43 views
1

我在MVC控制器的操作中有一个json字符串。我想发送它作为JSON对象查看。我该如何解决这个问题?如何发送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 }; 
} 

回答

5
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 
    ); 
}