zoukankan      html  css  js  c++  java
  • JSON 的封装和解析

     下面是一个演示JSON数据从 对象转换成JSON,最后翻译成对象 的一个演示实例代码。



    //MapList转换成json, 然后再 解释读出来里面的元素 @Test public String testJSON(){ Map map1 = new HashMap(); map1.put( "name", "json" ); map1.put( "bool", Boolean.TRUE ); map1.put( "int", new Integer(1) ); map1.put( "float",0.5f); Map map2 = new HashMap(); map2.put( "name", "json2" ); map2.put( "bool", Boolean.TRUE ); map2.put( "int", new Integer(1) ); map2.put( "float",0.6f); List list = new ArrayList(); list.add(map1); list.add(map2); Map map_main = new HashMap(); map_main.put( "error_no", "error_no" ); map_main.put( "error_info","error_info" ); map_main.put("result", list); JSONObject jsonObject = JSONObject.fromObject(map_main); System.out.println( jsonObject.toString() ); List arrayList = (List)JSONArray.toCollection(jsonObject.getJSONArray("result")); for(Object object : arrayList){ JSONObject jsonObject_temp = JSONObject.fromObject( object ); System.out.println(jsonObject_temp.get("name")); } return jsonObject.toString(); }

      

    JAVA端的对HTTP的JSON访问参照 http://www.cnblogs.com/mywebname/articles/2130636.html

  • 相关阅读:
    闭包 (Closure)
    RSA算法
    HTTPS
    SSH
    HDU1754 I hate it_线段树(入门级别)
    HDU1166 敌兵布阵_线段树
    c++运算符优先级表
    归并排序练习.
    HDU 1969 精度二分
    uva10944 状态压缩bfs or DP
  • 原文地址:https://www.cnblogs.com/hedan/p/3316428.html
Copyright © 2011-2022 走看看