JSON 对象是 JavaScipt 对象的自定义对象
1. 字符串转化为 JSON 对象, 可用 "(",")" 拼接
也可以用 $.parseJSON() 进行转化
2.JSON.stringify 函数的作用是将一个 javascript 对象, 转换为 JSON 格式的字符串.
3.JSONObject json=JSONObject.fromObject(data); 转化为 JSON 对象
4.
Hero hero = (Hero)JSONObject.toBean(json,Hero.
class
); z 转化为 Hero 对象
5.JSONObject json= new
JSONObject(); 创建 Json 对象
获取多数组的时候
- String result =JSONSerializer.toJSON(heros).toString();
- response.setContentType("text/html;charset=utf-8");
- response.getWriter().print(result);
单个数据
- Hero hero = new Hero();
- hero.setName("盖伦");
- hero.setHp(353);
- JSONObject json= new JSONObject();
- json.put("hero", JSONObject.fromObject(hero));
- response.setContentType("text/html;charset=utf-8");
- response.getWriter().print(json);
来源: http://www.bubuko.com/infodetail-2562233.html