使用alibaba的fastjson:
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @Autowired private userService userService; @RequestMapping("findall") @ResponseBody public String findall() { //从数据库中取出ArrayList数据 ArrayList<infor> all = userService.findAll(); JSONArray objects = JSON.parseArray(JSONObject.toJSONString(all)); //或者 JSONArray objects = JSON.parseArray(JSONObject.toJSONString(all)); return objects.toJSONString(); //或者 return objects.toString(); }