Convert Object to JSON in MVC 4

前端 未结 3 1882
被撕碎了的回忆
被撕碎了的回忆 2021-02-03 21:30

I am converting an object to JSON using JavaScriptSerializer and I can see this JSON output in server code:

[{\"UserId\":1,\"UserName\":\"Admin\"}]
         


        
3条回答
  •  不知归路
    2021-02-03 22:04

    If you are using the Razor view engine you need to use the Html.Raw method:

    
    

    Notice the usage of the Json.Encode method which is shorter and equivalent to new JavaScriptSerializer().Serialize().

提交回复
热议问题