XS993126
站在巅峰的小熊
采纳率50%
2015-12-12 01:20

怎么获取type为2的后面的所有电力公司name和code

已结题

[{"code":"D1_3600","name":"电费缴纳","type":"2","categories":[{"code":"D1_3600_8401","name":"合肥供电公司"},{"code":"D1_3600_0101","name":"肥东供电公司"},{"code":"D1_3600_0102","name":"肥西供电公司"},{"code":"D1_3600_0103","name":"长丰供电公司"},{"code":"D1_3600_8101","name":"安徽电力省公司"}]},{"code":"D3_3600","name":"燃气费缴纳","type":"3","categories":[{"code":"D3_3600_00AH","name":"合肥燃气"}]},{"code":"I1_3600","name":"联通缴费","type":"5","categories":[{"code":"I1_3600_1305","name":"安徽联通"}]},{"code":"J0_3600","name":"彩票投注","type":"34","categories":[{"code":"J0_3600_00AH","name":"安徽福彩"},{"code":"J0_3600_00ZS","name":"招商福彩"},{"code":"J0_3600_00NH","name":"农行福彩"}]},{"code":"D4_3600","name":"水费缴纳","type":"1","categories":[{"code":"D4_3600_00HF","name":"合肥供水"}]},{"code":"I1_3600","name":"移动缴费","type":"4","categories":[{"code":"I1_3600_000A","name":"安徽移动"}]},{"code":"G1_3600","name":"交通罚款","type":"26","categories":[{"code":"G1_3600_3602","name":"交警罚款缴费(安徽非税)"},{"code":"G1_3600_0000","name":"违章代办(第三方处理)"}]},{"code":"I1_3600","name":"有线电视缴费","type":"19","categories":[{"code":"I1_3600_3610","name":"合肥市有线电视"},{"code":"I1_3600_200A","name":"合肥市有线电视"}]},{"code":"S2_3600","name":"医疗充值","type":"47","categories":[{"code":"S2_3600_0000","name":"医疗-健康之路"}]},{"code":"I1_3600","name":"电信手机缴费","type":"15","categories":[{"code":"I1_3600_4550","name":"安徽电信手机缴费(滁州)"},{"code":"I1_3600_4551","name":"安徽电信手机缴费(合肥)"},{"code":"I1_3600_4552","name":"安徽电信手机缴费(蚌埠)"},{"code":"I1_3600_4553","name":"安徽电信手机缴费(芜湖)"},{"code":"I1_3600_4554","name":"安徽电信手机缴费(淮南)"},{"code":"I1_3600_4555","name":"安徽电信手机缴费(马鞍山)"},{"code":"I1_3600_4556","name":"安徽电信手机缴费(安庆)"},{"code":"I1_3600_4557","name":"安徽电信手机缴费(宿州)"},{"code":"I1_3600_4558","name":"安徽电信手机缴费(阜阳)"},{"code":"I1_3600_4559","name":"安徽电信手机缴费(黄山)"},{"code":"I1_3600_4560","name":"安徽电信手机缴费(亳州)"},{"code":"I1_3600_4561","name":"安徽电信手机缴费(淮北)"},{"code":"I1_3600_4562","name":"安徽电信手机缴费(铜陵)"},{"code":"I1_3600_4563","name":"安徽电信手机缴费(宣城)"},{"code":"I1_3600_4564","name":"安徽电信手机缴费(六安)"},{"code":"I1_3600_4566","name":"安徽电信手机缴费(池州)"}]},{"code":"I1_3600","name":"电信固话宽带缴费","type":"44","categories":[{"code":"I1_3600_2550","name":"安徽电信固话缴费(滁州)"},{"code":"I1_3600_2551","name":"安徽电信固话缴费(合肥)"},{"code":"I1_3600_2552","name":"安徽电信固话缴费(蚌埠)"},{"code":"I1_3600_2553","name":"安徽电信固话缴费(芜湖)"},{"code":"I1_3600_2554","name":"安徽电信固话缴费(淮南)"},{"code":"I1_3600_2555","name":"安徽电信固话缴费(马鞍山)"},{"code":"I1_3600_2556","name":"安徽电信固话缴费(安庆)"},{"code":"I1_3600_2557","name":"安徽电信固话缴费(宿州)"},{"code":"I1_3600_2558","name":"安徽电信固话缴费(阜阳)"},{"code":"I1_3600_2559","name":"安徽电信固话缴费(黄山)"},{"code":"I1_3600_2560","name":"安徽电信固话缴费(亳州)"},{"code":"I1_3600_2561","name":"安徽电信固话缴费(淮北)"},{"code":"I1_3600_2562","name":"安徽电信固话缴费(铜陵)"},{"code":"I1_3600_2563","name":"安徽电信固话缴费(宣城)"},{"code":"I1_3600_2564","name":"安徽电信固话缴费(六安)"},{"code":"I1_3600_2566","name":"安徽电信固话缴费(池州)"},{"code":"I1_3600_5550","name":"安徽电信宽带缴费(滁州)"},{"code":"I1_3600_5551","name":"安徽电信宽带缴费(合肥)"},{"code":"I1_3600_5552","name":"安徽电信宽带缴费(蚌埠)"},{"code":"I1_3600_5553","name":"安徽电信宽带缴费(芜湖)"},{"code":"I1_3600_5554","name":"安徽电信宽带缴费(淮南)"},{"code":"I1_3600_5555","name":"安徽电信宽带缴费(马鞍山)"},{"code":"I1_3600_5556","name":"安徽电信宽带缴费(安庆)"},{"code":"I1_3600_5557","name":"安徽电信宽带缴费(宿州)"},{"code":"I1_3600_5558","name":"安徽电信宽带缴费(阜阳)"},{"code":"I1_3600_5559","name":"安徽电信宽带缴费(黄山)"},{"code":"I1_3600_5560","name":"安徽电信宽带缴费(亳州)"},{"code":"I1_3600_5561","name":"安徽电信宽带缴费(淮北)"},{"code":"I1_3600_5562","name":"安徽电信宽带缴费(铜陵)"},{"code":"I1_3600_5563","name":"安徽电信宽带缴费(宣城)"},{"code":"I1_3600_5564","name":"安徽电信宽带缴费(六安)"},{"code":"I1_3600_5566","name":"安徽电信宽带缴费(池州)"}]},{"code":"S0_3600","name":"税费","type":"20","categories":[{"code":"S0_3600_ACP01","name":"安徽国税"}]}]

  • 点赞
  • 收藏
  • 复制链接分享

6条回答

  • supolovedn supolovedn 6年前

    这种比较复杂的json,许多库都不好解析,最后我是用gson来解析的。帮你写好了,你自己试试。
    如果没有gson库可以到这里下载
    http://download.csdn.net/detail/supolovedn/9349263

    首先写一个类 TestJsonFromObject.java
    public class TestJsonFromObject {
    public String code;
    public String name;
    public String type;

      List<categoriesItem> categories;
    
      class categoriesItem { 
        public String code; 
        public String name; 
      } 
    

    }

    在需要解析的地方写
    Gson gson = new Gson();
    List ps = gson.fromJson(mJson, new TypeToken>(){}.getType());
    用for循环就可以变量list的元素了。

    点赞 1 评论 复制链接分享
  • supolovedn supolovedn 6年前

    上面输出的问题,我重新回答一下
    这种比较复杂的json,许多库都不好解析,最后我是用gson来解析的。帮你写好了,你自己试试。
    如果没有gson库可以到这里下载
    http://download.csdn.net/detail/supolovedn/9349263

    首先写一个类 TestJsonFromObject.java

     public class TestJsonFromObject {
          public String code; 
          public String name; 
          public String type; 
    
          List<categoriesItem> categories;
    
          class categoriesItem { 
            public String code; 
            public String name; 
          } 
    }
    

    在需要解析的地方写

    Gson gson = new Gson(); 
    List<TestJsonFromObject> ps = gson.fromJson(mJson, new TypeToken<List<TestJsonFromObject>>(){}.getType());
    

    用for循环就可以变量list的元素了。

    点赞 1 评论 复制链接分享
  • Royal_lr Royal_lr 6年前

    封装一个实体类ChildCode,,属性为(code,name),,在封装一个实体类为FeeCode,,属性为(code,name,type,List categories),,,就行了

    点赞 评论 复制链接分享
  • XS993126 站在巅峰的小熊 6年前

    我想把它转换成Javabean的话,这字符串太多了,他会不会一直覆盖

    点赞 评论 复制链接分享
  • liaoyi_ liaoyi_ 6年前

    用Gson解析json字符串吧,这样简单一些。你只需要封装一个实体类就行了,或者用Android 自己提供的类jsonObject ,jsonArray 来解析你想要的字段

    点赞 评论 复制链接分享
  • XS993126 站在巅峰的小熊 6年前

    求方法,本人新手菜鸟,求大神罩我

    点赞 评论 复制链接分享

相关推荐