importjava.util.ArrayList;
importjava.util.HashMap;
importjava.util.List;
importjava.util.Map;
importjavax.servlet.http.HttpServletRequest;
importnet.sf.json.JSONObject;
.
.
.
if(CollectionUtil.isNotEmpty(userModelList)){
List<JSONObject>list=newArrayList<JSONObject>();
Mapo=newHashMap();
for(UserModeluserModel:userModelList){
Mapmap=newHashMap();
map.put("id",userModel.getUser_id_site());
map.put("name",userModel.getUser_nike_name());
map.put("image",userModel.getUser_image_big());
JSONObjectjsonobj=JSONObject.fromObject(map);
list.add(jsonobj);
}
Mapoo=newHashMap();
oo.put("users",list.toArray());
Mapstatus=newHashMap();
oo.put("status","ok");
JSONObjectjsonobj=JSONObject.fromObject(oo);
jsonobj.putAll(status);
o.put("jsonp",jsonobj);
System.out.println(o.toString());
returno.toString();
}
//////////结果类似这样:
{jsonp={"users":[{"id":"1","name":"客服NO1","image":null},{"id":"asfdafasd","name":"sdaf","image":"sadfas"},{"id":"asfdafasd","name":"sdaf","image":"sadfas"}],"status":"ok"}}
你也可以继续嵌套构造多级