21
08/2014
c#生成json对象
public static string api_return(bool status=true, string message="ok", Object custom_ary=null, string errorCode="")
{
System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
Dictionary<string, object> result = new Dictionary<string, object>();
result["status"] = status ? "success" : "error";
result["message"] = message;
if (!status)
{
result["errorCode"] = errorCode;
}
result["data"] = custom_ary;
return jss.Serialize(result);
}注意需要添加引用(非web项目):system.web.extension
转载请注明:康瑞部落 » c#生成json对象

0 条评论