{
"err_code": 0, //错误码,int类型
"err_msg":"", //错误描述,String类型
"data_array": {
"data_list": [
{"key1":"","key2":"" },{"key1":"" , "key2":"" }
],
"page_now": 1, //当前页
"page_size": 10, //每页多少条
"page_count": 20 //总页数
}
}
//生成以上JSON?
public class AjaxjsonResultlists<T>
{
public int err_code { get; set; }
public string err_msg { get; set; }
public string data_array { get; set; }
}
public class AjasjsonResultlist<T>
{
public List<T> data_list { get; set; }
public int page_now { get; set; } //当前页
public int page_size { get; set; } //每页多少条
public int page_count { get; set; } //总页数
}
public string test()
{
AjaxjsonResultlists<Class> r = new AjaxjsonResultlists<Class>();
AjasjsonResultlist<Class> rs = new AjasjsonResultlist<Class>();
JavaScriptSerializer js = new JavaScriptSerializer();
string _json_str = string.Empty;
List<Class> list = new List<Class>();
rs.data_list = list;
rs.page_count = list.Count;
rs.page_now = 0;
rs.page_size = 10;
r.err_code = 0;
r.err_msg = "查询信息成功!";
r.data_array = _json_str;
_json_str = js.Serialize(r);
return _json_str ;
}
这样写生成的有问题,请问大神,我该怎么改呀!绕去绕来,都晕了。
public class AjaxjsonResultlists<T>
{
public int err_code { get; set; }
public string err_msg { get; set; }
public AjasjsonResultlist<T> data_array { get; set; }
}
public class AjasjsonResultlist<T>
{
public List<T> data_list { get; set; }
public int page_now { get; set; } //当前页
public int page_size { get; set; } //每页多少条
public int page_count { get; set; } //总页数
}
rs.data_list = list;
rs.page_count = list.Count;
rs.page_now = 0;
rs.page_size = 10;
r.err_code = 0;
r.err_msg = "查询信息成功!";
r.data_array = rs;
_json_str = js.Serialize(r);
public class ResultObj
{
public int err_code{ get; set; }
public string err_msg{ get; set; }
public object data_array{ get; set; }
}
public ActionResult Test(){
Object obj= ...; //放结果的数组对象
return Json(new ResultObj(){err_code=1,err_msg="你错了",data_array=new { data_list=obj,page_now=1, page_size =9,page_count =5}}, JsonRequestBehavior.AllowGet);
}