コード例 #1
0
  // 对address.json进行解析
  private List<Dialog_forlist> jSON2List2(String jsonPath) throws JSONException {
    List<Dialog_forlist> list = new ArrayList<>();
    InputStream is = AssetManagerUtils.getData(jsonPath, ReleaseActivity.this);
    String str = StreamTools.readStream(is);

    JSONObject object = new JSONObject(str);
    JSONArray jsonArray = object.getJSONArray("city");
    JSONObject jsonObject = jsonArray.getJSONObject(0);
    JSONArray jsonArray1 = jsonObject.getJSONArray("tdistrict");
    for (int i = 0; i < jsonArray1.length(); i++) {
      Dialog_forlist dialog_forlist = new Dialog_forlist();
      List<String> list_city = new ArrayList<>();
      if (i == 0) {
        JSONObject jsonObject1 = jsonArray1.getJSONObject(i);
        dialog_forlist.setName(jsonObject1.getString("name"));
        list_city.add("不限");
        dialog_forlist.setList(list_city);
      } else {
        JSONObject jsonObject1 = jsonArray1.getJSONObject(i);
        dialog_forlist.setName(jsonObject1.getString("name"));
        JSONArray jsonArray2 = jsonObject1.getJSONArray("bussinessareaList");
        for (int j = 0; j < jsonArray2.length(); j++) {
          JSONObject jsonObject2 = jsonArray2.getJSONObject(j);
          list_city.add(jsonObject2.getString("name"));
        }
        dialog_forlist.setList(list_city);
      }
      list.add(dialog_forlist);
    }

    return list;
  }
コード例 #2
0
  // 对.json进行解析
  private List<Dialog_forlist> jSON2List(
      String jsonPath, String outName, String outName2, String inName, String id)
      throws JSONException {
    List<Dialog_forlist> list = new ArrayList<>();
    InputStream is = AssetManagerUtils.getData(jsonPath, ReleaseActivity.this);
    String str = StreamTools.readStream(is);

    JSONArray jsonArray = new JSONArray(str);
    for (int i = 0; i < jsonArray.length(); i++) {
      Dialog_forlist dialog_forlist = new Dialog_forlist();
      JSONObject jsonObject = jsonArray.getJSONObject(i);
      dialog_forlist.setName(jsonObject.getString(outName));
      JSONArray jsonArray2 = jsonObject.getJSONArray(outName2);
      List<String> list_city = new ArrayList<>();
      List<Integer> list_id = new ArrayList<>();
      for (int j = 0; j < jsonArray2.length(); j++) {
        JSONObject jsonObject2 = jsonArray2.getJSONObject(j);
        list_city.add(jsonObject2.getString(inName));
        list_id.add(jsonObject2.getInt(id));
      }
      dialog_forlist.setList(list_city);
      dialog_forlist.setList_id(list_id);
      list.add(dialog_forlist);
    }

    return list;
  }