码迷,mamicode.com
首页 > Web开发 > 详细

JSON格式的转换

时间:2018-04-14 16:27:01      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:个数   iter   格式   put   sci   parse   tostring   ace   plain   

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);

 

JSON格式的转换

标签:个数   iter   格式   put   sci   parse   tostring   ace   plain   

原文地址:https://www.cnblogs.com/zxj-262410/p/8832024.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!