JSONResult to String

后端 未结 3 478
轮回少年
轮回少年 2020-12-02 15:19

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         


        
相关标签:
3条回答
  • 2020-12-02 15:39
    json = " { \"success\" : false, \"errors\": { \"text\" : \"绑定登录失败!\" } }";            
    return new MemoryStream(Encoding.UTF8.GetBytes(json));
    
    0 讨论(0)
  • 2020-12-02 15:47

    You're looking for the JavaScriptSerializer class, which is used internally by JsonResult:

    string json = new JavaScriptSerializer().Serialize(jsonResult.Data);
    
    0 讨论(0)
  • 2020-12-02 15:56

    You can also use Json.NET.

    return JsonConvert.SerializeObject(jsonResult.Data);
    
    0 讨论(0)
提交回复
热议问题