public void run() { try { String url = "&&user_auth_id=" + user_auth_id + "&&patient_info_id=" + patient_info_id + "&&menu_lib_id=" + menu_lib_id; L.d("aa", "value_str=" + value_str); if ("添加".equals(title_name.getText().toString())) { create_code = HttpUtil.doPost(NetUrlAddress.Common_create_url + url, value_str); } else { L.d("aa", "value_str_edit=" + value_str); update_code = HttpUtil.doPost(NetUrlAddress.Common_update_url + url, value_str); } Message message = new Message(); message.what = 1; handler.sendMessage(message); } catch (Exception e) { L.d("aa", "MyThread出错了"); e.printStackTrace(); Message message = new Message(); message.what = 1; handler.sendMessage(message); } }
/** * 解析数据JSON * * @param strResult * @return */ public static ArrayList<NormalTableFinalModel> parseJson( String strResult, ArrayList<NormalTableModel> list_info) { ArrayList<NormalTableModel> list_model = null; ArrayList<NormalTableFinalModel> list_final_model = null; NormalTableFinalModel model = null; try { JSONObject jsonObject = new JSONObject(strResult); JSONArray jsonArray = jsonObject.getJSONArray("data"); list_final_model = new ArrayList<>(); if (!jsonArray.toString().equals("[]")) { for (int i = jsonArray.length() - 1; i >= 0; i--) { JSONObject object = jsonArray.getJSONObject(i); list_model = new ArrayList<>(); try { list_model = deepCopy(list_info); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } for (int j = 0; j < list_model.size(); j++) { list_model.get(j).setMiddleText(object.getString(list_model.get(j).getName())); } model = new NormalTableFinalModel(); model.setIsEmpty("no"); model.setModel_name(jsonObject.getString("model_name")); model.setId(jsonArray.getJSONObject(i).getString("id")); model.setList_model(list_model); list_final_model.add(model); } } else { model = new NormalTableFinalModel(); model.setIsEmpty("yes"); model.setModel_name(jsonObject.getString("model_name")); list_model = new ArrayList<>(); try { list_model = deepCopy(list_info); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } model.setList_model(list_model); list_final_model.add(model); } } catch (Exception e) { L.d("yy", "NormalTableFinalModel Parse Error"); e.printStackTrace(); } return list_final_model; }
/** * 添加时,拼接json * * @param list_model_three * @param list_model_one * @return */ private String getJsonDataAdd( List<Model_three> list_model_three, List<Model_one> list_model_one) { JSONArray arr_three = null; JSONObject jsonObject_model_one = null; JSONArray arr_two = null; try { arr_two = new JSONArray(); for (int m = 0; m < list_model_one.get(0).getHeader_questions().size(); m++) { arr_three = new JSONArray(); for (int n = 0; n < list_model_one.get(0).getHeader_questions().get(m).getQuestions().size(); n++) { JSONObject jsonObject_three = new JSONObject(); Model_three model_three = list_model_one.get(0).getHeader_questions().get(m).getQuestions().get(n); jsonObject_three.put("question", model_three.getQuestion()); jsonObject_three.put("value", model_three.getValue()); jsonObject_three.put("in_sum", model_three.isIn_sum()); arr_three.put(jsonObject_three); } JSONObject jsonObject_model_two = new JSONObject(); Model_two model_two = list_model_one.get(0).getHeader_questions().get(m); jsonObject_model_two.put("header", model_two.getHeader()); jsonObject_model_two.put("questions", arr_three); arr_two.put(jsonObject_model_two); } Model_one model_one = list_model_one.get(0); jsonObject_model_one = new JSONObject(); // arr_one=new JSONArray(); jsonObject_model_one.put("evaluation_person", person.getText().toString()); jsonObject_model_one.put("evaluation_time_note", spinner_value); jsonObject_model_one.put("evaluation_time", date_tv.getText().toString()); jsonObject_model_one.put("has_sum", model_one.isHas_sum()); jsonObject_model_one.put("has_grade", model_one.isHas_grade()); String groupid = getGroupId(); jsonObject_model_one.put("groupid", groupid); jsonObject_model_one.put("header_questions", arr_two); // params.put("model",jsonObject_model_one); // arr_one.put(jsonObject_model_one); // jsonData = new JSONStringer().object().key("data").value(arr_one).endObject().toString(); // L.d("aa", "arr_one=" + arr_one.toString()); L.d("aa", "jsonObject_model_one=" + jsonObject_model_one.toString()); // L.d("aa", " jsonData=" + jsonData); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return jsonObject_model_one.toString(); }