I have a JsonResult
that is working fine, and returning JSON from some POCO\'s. I want to save the JSON as a string in a DB.
public JsonRes
json = " { \"success\" : false, \"errors\": { \"text\" : \"绑定登录失败!\" } }";
return new MemoryStream(Encoding.UTF8.GetBytes(json));
You're looking for the JavaScriptSerializer class, which is used internally by JsonResult:
string json = new JavaScriptSerializer().Serialize(jsonResult.Data);
You can also use Json.NET.
return JsonConvert.SerializeObject(jsonResult.Data);