我有:
Function SaveAnswers(ByVal collection As FormCollection) As ActionResult
End Funciton我想将集合转换为JSON,我以为有一个序列化程序可以做到这一点,但似乎找不到它?
发布于 2009-08-04 18:01:09
NewtonSoft.JSON
http://james.newtonking.com/pages/json-net.aspx
发布于 2011-12-04 17:43:54
序列化FormCollection对象对我不起作用,序列化了键,但值不起作用。
我想使用一种简单的方法来“记录”FormCollection值,以便在测试用例中重用。为此,我创建了一个扩展方法:
public static string ToJSON(this System.Web.Mvc.FormCollection collection)
{
var list = new Dictionary<string, string>();
foreach (string key in collection.Keys)
{
list.Add(key, collection[key]);
}
return new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(list);
}发布于 2009-08-05 07:55:21
的确有。在c#中:
return Json(object/array/whatever);它返回一个JsonResult,它是一个ActionResult,所以它“适合”你的函数,因为它已经存在了。
詹姆斯
https://stackoverflow.com/questions/1228940
复制相似问题