JSon.net和的ActionResult [英] JSon.net And ActionResult
本文介绍了JSon.net和的ActionResult的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
林建设JObject自己并希望将其作为返回ActionResult的。我不想创建并序列化的数据对象。
例如
公众的ActionResult测试(字符串ID)
{
VAR解析度=新JObject();
JArray阵列=新JArray();
array.Add(手动文字);
array.Add(新的DateTime(2000,5,23));
RES [ID] = 1;
RES [结果] =阵列;
返回JSON(RES); // ???????
}
解决方案
您应该只能够做到这一点在你的操作方法:
返回内容(res.ToString(),应用/ JSON);
Im building a JObject myself and want to return it as ActionResult. I dont want to create and then serialize a data object
For example
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); //???????
}
解决方案
You should just be able to do this in your action method:
return Content( res.ToString(), "application/json" );
这篇关于JSon.net和的ActionResult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文