Joson的简单用法

Josn实体类如下:

 public class Result

    {

        public int StatusCode { get; set; }

        public string Message { get; set; }

    }
View Code

传真操作方法如下:

Result result = new Result { StatusCode = 300, Message = "操作失败", IsSucceed=false };

            JavaScriptSerializer serializer = new JavaScriptSerializer();

           string strResult= serializer.Serialize(result);
View Code

相当于如下方法:

public string success()

        {

            return "{\"statusCode\":\"200\", \"message\":\"操作成功!\"}";
View Code

 

你可能感兴趣的:(简单用法)