// 对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; }
// 对.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; }
private void dialogRoommate3() throws JSONException { AlertDialog.Builder builder = new AlertDialog.Builder(ReleaseActivity.this); View view = View.inflate(ReleaseActivity.this, R.layout.dialog_addroommate3, null); TextView textView_title = (TextView) view.findViewById(R.id.dialog_title); textView_title.setText("职业"); final ListView listView = (ListView) view.findViewById(R.id.dialog_listview); final ListView listView2 = (ListView) view.findViewById(R.id.dialog_listview2); final ListView listView3 = (ListView) view.findViewById(R.id.dialog_listview3); builder.setView(view); InputStream is = AssetManagerUtils.getData("tjob.json", ReleaseActivity.this); final String str = StreamTools.readStream(is); final List<String> list1 = new ArrayList<>(); final List<String> list2 = new ArrayList<>(); final List<String> list3 = new ArrayList<>(); final List<String> list3_id = new ArrayList<>(); final JSONArray jsonArray = new JSONArray(str); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); list1.add(jsonObject.getString("vocation")); } final Dialog dialog = builder.show(); listView.setAdapter( new ArrayAdapter(ReleaseActivity.this, R.layout.dialog_listview_layout, list1)); listView.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { JSONArray jsonArray = null; list2.clear(); list3.clear(); list3_id.clear(); if (adapter3 != null) { adapter3.clear(); } final int p = position; try { jsonArray = new JSONArray(str); for (int i = 0; i < jsonArray.length(); i++) { if (i == position) { JSONObject jsonObject = jsonArray.getJSONObject(position); JSONArray jsonArray1 = jsonObject.getJSONArray("vocationChildList"); for (int j = 0; j < jsonArray1.length(); j++) { JSONObject jsonObject1 = jsonArray1.getJSONObject(j); list2.add(jsonObject1.getString("vocationChild")); } } } } catch (JSONException e) { e.printStackTrace(); } adapter2 = new ArrayAdapter(ReleaseActivity.this, R.layout.dialog_listview_layout, list2); adapter2.notifyDataSetChanged(); listView2.setAdapter(adapter2); listView2.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { JSONArray jsonArray = null; list3.clear(); list3_id.clear(); try { jsonArray = new JSONArray(str); for (int i = 0; i < jsonArray.length(); i++) { if (i == p) { JSONObject jsonObject = jsonArray.getJSONObject(p); JSONArray jsonArray1 = jsonObject.getJSONArray("vocationChildList"); for (int j = 0; j < jsonArray1.length(); j++) { if (j == position) { JSONObject jsonObject1 = jsonArray1.getJSONObject(position); JSONArray jsonArray2 = jsonObject1.getJSONArray("jobList"); for (int k = 0; k < jsonArray2.length(); k++) { JSONObject jsonObject2 = jsonArray2.getJSONObject(k); list3.add(jsonObject2.getString("jobName")); list3_id.add(Integer.toString(jsonObject2.getInt("jobId"))); } } } } } } catch (JSONException e) { e.printStackTrace(); } adapter3 = new ArrayAdapter( ReleaseActivity.this, R.layout.dialog_listview_layout, list3); adapter3.notifyDataSetChanged(); listView3.setAdapter(adapter3); listView3.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick( AdapterView<?> parent, View view, int position, long id) { release_job_tv2.setText(list3.get(position)); map_release.put("job2", list3_id.get(position)); dialog.dismiss(); } }); } }); } }); }