Json.Net和ActionResult

我自己建立一个JObject,并希望将其作为ActionResult返回。 我不想创建然后序列化数据对象

例如

public ActionResult Test(string id) { var res = new JObject(); JArray array = new JArray(); array.Add("Manual text"); array.Add(new DateTime(2000, 5, 23)); res["id"] = 1; res["result"] = array; return Json(res); //??????? } 

您应该只能在您的操作方法中执行此操作:

 return Content( res.ToString(), "application/json" ); 

如果你负责JSON格式化,只需return JSON Formatted string

 public string Test(string id) { var res = new JObject(); JArray array = new JArray(); array.Add("Manual text"); array.Add(new DateTime(2000, 5, 23)); res["id"] = 1; res["result"] = array; return YourJSONSerializedString; } 

else使用内置的JsonResult (ActionResult)

  public JsonResult Test(string id) { return Json(objectToConvert); }