zoukankan      html  css  js  c++  java
  • 对于json数据的应用01

    1、通过访问接口返回一组json格式的数据。

    例子如下:

    String aa = "{"result":"1","roleinfo":[{"gender":"f","name":"%E4%B8%80%E5%8C%BA%E7%AC%AC%E4%B8%80","grade":5,"profession":"%E8%90%9D%E8%8E%89","createDate":"2013-04-25 09:28:24","playerforce":"668"},{"gender":"f","name":"%E4%B8%80%E5%8C%BA%E7%AC%AC%E4%BA%8C","grade":1,"profession":"%E8%90%9D%E8%8E%89","createDate":"2013-04-25 09:40:09","playerforce":"210"},{"gender":"f","name":"%E4%B8%80%E5%8C%BA%E7%AC%AC%E4%B8%89","grade":1,"profession":"%E8%90%9D%E8%8E%89","createDate":"2013-04-25 09:40:38","playerforce":"210"},{"gender":"f","name":"%E4%B8%80%E5%8C%BA%E7%AC%AC%E5%9B%9B","grade":1,"profession":"%E8%90%9D%E8%8E%89","createDate":"2013-04-25 09:41:02","playerforce":"210"}]}";

    解释:返回值是一个对象,里面有两个参数result和roleinfo。roleinfo的内容是json数组。

    2、将字符串转换成json对象。

    JSONObject bb= JSONObject.fromObject(aa);

    3、再将bb中的roleinfo截出来,放进json数组中。

    JSONArray cc= JSONArray.fromObject(bb.getString("roleinfo"));

    4、读cc中的属性name。

    String dd ="";

    for(int i=0;i<cc.size();i++)
    {
            JSONObject dd= JSONObject.fromObject(cc.getString(i));
            ee+= java.net.URLDecoder.decode(dd.getString("name"),"UTF-8")+",";//转换格式
    }

  • 相关阅读:
    转:spring 的控制反转
    jsp 页面间传递参数
    Struts-config.xml配置文件《action-mappings》元素的详解
    转:装饰模式
    转:策略模式
    MyBatis的动态SQL详解
    MyBatis配置
    spring与mybatis三种整合方法
    sqlserver 脚本 多条记录遍历
    SQL Server 游标使用
  • 原文地址:https://www.cnblogs.com/jirglt/p/3049060.html
Copyright © 2011-2022 走看看