コード例 #1
0
    public List<Professioninfo> getJSONParserResult(String JSONString, String key) {
      List<Professioninfo> list = new ArrayList<Professioninfo>();
      JsonObject result = new JsonParser().parse(JSONString).getAsJsonObject().getAsJsonObject(key);

      Iterator iterator = result.entrySet().iterator();
      while (iterator.hasNext()) {
        Map.Entry<String, JsonElement> entry = (Entry<String, JsonElement>) iterator.next();
        Professioninfo professioninfo = new Professioninfo();

        professioninfo.setProfession_name(entry.getValue().getAsString());
        professioninfo.setId(entry.getKey());
        industry_list_code.add(entry.getKey());
        list.add(professioninfo);
      }
      System.out.println(industry_list_code.size());
      return list;
    }
コード例 #2
0
    public HashMap<String, List<Professioninfo>> getJSONParserResultArray(
        String JSONString, String key) {
      HashMap<String, List<Professioninfo>> hashMap = new HashMap<String, List<Professioninfo>>();
      JsonObject result = new JsonParser().parse(JSONString).getAsJsonObject().getAsJsonObject(key);

      Iterator iterator = result.entrySet().iterator();
      while (iterator.hasNext()) {
        Map.Entry<String, JsonElement> entry = (Entry<String, JsonElement>) iterator.next();
        List<Professioninfo> list = new ArrayList<Professioninfo>();
        JsonArray array = entry.getValue().getAsJsonArray();
        for (int i = 0; i < array.size(); i++) {
          Professioninfo professioninfo = new Professioninfo();
          professioninfo.setProfession_name(array.get(i).getAsJsonArray().get(0).getAsString());
          professioninfo.setId(array.get(i).getAsJsonArray().get(1).getAsString());
          profession_list_code.add(array.get(i).getAsJsonArray().get(1).getAsString());
          list.add(professioninfo);
        }
        hashMap.put(entry.getKey(), list);
      }
      return hashMap;
    }