package com.puyi.mobilehospital.http.orders;import java.util.ArrayList;import org.json.JSONArray;import org.json.JSONException;import org.json.JSONObject;import android.os.Message;import android.util.Log;import com.puyi.mobilehospital.entity.costManager.CancelMedicine;import com.puyi.mobilehospital.http.connection.HttpCommand;import com.puyi.mobilehospital.utils.LogUtil;/** *  * @类名称: CancelMedicineOrder  * @类描述:取消领药 * @作 者: 胡高山 * @创建时间: 2012-4-26 下午7:43 */public class CancelMedicineOrder implements HttpCommand {private static final String TAG = "CancelMedicineOrder";private String json;private String hospitalNo;@Overridepublic void execute(JSONObject parameter, Message msg) throws Exception {// 填入假数据,模拟已经从服务器返回包含数据的Json,解析后通过Message传出,在界面由Handler接收后显示JSONObject jparameter = parameter;hospitalNo = (String) jparameter.get("hospitalNo");json = setJson(hospitalNo);if (null != json) {//有假数据Log.i(TAG, "execute setJson no null ");JSONObject jsnobj;try {jsnobj = new JSONObject(json);int code = jsnobj.optInt("code");String errormsg = jsnobj.optString("message");LogUtil.d(TAG, "code: " + code);if (code == 0) {ArrayList<CancelMedicine> cancelList = messageParse(json);Log.i(TAG, "messageParse json OK 53");msg.obj = cancelList;msg.arg1 = code;} else if (code == 1) {msg.obj = errormsg;msg.arg1 = code;Log.i(TAG, "messageParse json error 60");}} catch (JSONException e) {// TODO Auto-generated catch blocke.printStackTrace();}}msg.sendToTarget();}/** * 解析响应的JSON数据 PatientInfos */public ArrayList<CancelMedicine> messageParse(String json) {ArrayList<CancelMedicine> cancelList=new ArrayList<CancelMedicine>();try {JSONObject jsnobj = new JSONObject(json);// 总InfoJSONObject CancelMedicineInfo = jsnobj.optJSONObject("CancelMedicineInfo");JSONArray jaCancelMedicine=CancelMedicineInfo.optJSONArray("CancelMedicineList");//取消领药 CancelMedicine======================================================================================if(jaCancelMedicine.length()>0){CancelMedicine cancelMedicine;for(int i=0;i<jaCancelMedicine.length();i++){JSONObject object=jaCancelMedicine.optJSONObject(i);cancelMedicine=new CancelMedicine();cancelMedicine.hospitalNo=object.optString("hospitalNo");cancelMedicine.productName=object.optString("productName");cancelMedicine.standard=object.optString("standard");cancelMedicine.price=object.optDouble("price");cancelMedicine.applyNum=object.optInt("applyNum");cancelMedicine.totalMoney=object.optDouble("totalMoney");cancelMedicine.applyLab=object.optString("applyLab");cancelMedicine.provideLab=object.optString("provideLab");cancelMedicine.patientName=object.optString("patientName");cancelMedicine.applyDate=object.optString("applyDate");cancelList.add(cancelMedicine);}}}catch (JSONException e) {e.printStackTrace();}return cancelList;}@Overridepublic boolean onTimeOut(JSONObject parameter, Message msg) {// TODO Auto-generated method stubreturn false;}@Overridepublic void onException(JSONObject parameter, Message msg, Exception e) {// TODO Auto-generated method stub}// 假数据填入方法public String setJson(String hospitalNo) {String jsonstr = null;if (hospitalNo.equals("00000002")) {jsonstr = "{\"code\":0,\"message\":\"success\",\"CancelMedicineInfo\":{"+ "\"CancelMedicineList\":["+ "{\"hospitalNo\": \"00000002\",\"productName\":\"生血宁片\",\"standard\":\"0.5mg片\",\"price\":\"7.5\",\"applyNum\":\"2\",\"totalMoney\":\"15\",\"applyLab\":\"05病区\",\"provideLab\":\"药房\",\"patientName\":\"秦春华\",\"applyDate\":\"2011-10-05 0:30:25\"},"+ "{\"hospitalNo\": \"00000002\",\"productName\":\"生血宁片\",\"standard\":\"1.5mg片\",\"price\":\"5.5\",\"applyNum\":\"2\",\"totalMoney\":\"11\",\"applyLab\":\"05病区\",\"provideLab\":\"药房\",\"patientName\":\"秦春华\",\"applyDate\":\"2011-10-05 0:30:25\"},"+ "{\"hospitalNo\": \"00000002\",\"productName\":\"生血宁片\",\"standard\":\"2.5mg片\",\"price\":\"3.5\",\"applyNum\":\"2\",\"totalMoney\":\"7\",\"applyLab\":\"05病区\",\"provideLab\":\"药房\",\"patientName\":\"秦春华\",\"applyDate\":\"2011-10-05 0:30:25\"},"+ "{\"hospitalNo\": \"00000002\",\"productName\":\"生血宁片\",\"standard\":\"2.5mg片\",\"price\":\"6.5\",\"applyNum\":\"2\",\"totalMoney\":\"13\",\"applyLab\":\"05病区\",\"provideLab\":\"药房\",\"patientName\":\"秦春华\",\"applyDate\":\"2011-10-05 0:30:25\"},"+ "{\"hospitalNo\": \"00000002\",\"productName\":\"生血宁片\",\"standard\":\"0.15mg片\",\"price\":\"2.5\",\"applyNum\":\"2\",\"totalMoney\":\"5\",\"applyLab\":\"05病区\",\"provideLab\":\"药房\",\"patientName\":\"秦春华\",\"applyDate\":\"2011-10-05 0:30:25\"}"+ "]"+"}}";} else if (hospitalNo.equals("00000001")) {jsonstr = "{\"code\":0,\"message\":\"success\",\"CancelMedicineInfo\":{"+ "\"CancelMedicineList\":["+ "{\"hospitalNo\": \"00000001\",\"productName\":\"利可君片\",\"standard\":\"2.5mg片\",\"price\":\"6.5\",\"applyNum\":\"2\",\"totalMoney\":\"13\",\"applyLab\":\"01病区\",\"provideLab\":\"药房\",\"patientName\":\"范子毅\",\"applyDate\":\"2011-10-05 0:30:25\"},"+ "{\"hospitalNo\": \"00000001\",\"productName\":\"利可君片\",\"standard\":\"1.5mg片\",\"price\":\"5.5\",\"applyNum\":\"2\",\"totalMoney\":\"11\",\"applyLab\":\"01病区\",\"provideLab\":\"药房\",\"patientName\":\"范子毅\",\"applyDate\":\"2011-10-05 0:30:25\"},"+ "{\"hospitalNo\": \"00000001\",\"productName\":\"利可君片\",\"standard\":\"2.5mg片\",\"price\":\"3.5\",\"applyNum\":\"2\",\"totalMoney\":\"7\",\"applyLab\":\"01病区\",\"provideLab\":\"药房\",\"patientName\":\"范子毅\",\"applyDate\":\"2011-10-05 0:30:25\"},"+ "{\"hospitalNo\": \"00000001\",\"productName\":\"利可君片\",\"standard\":\"2.5mg片\",\"price\":\"6.5\",\"applyNum\":\"2\",\"totalMoney\":\"13\",\"applyLab\":\"01病区\",\"provideLab\":\"药房\",\"patientName\":\"范子毅\",\"applyDate\":\"2011-10-05 0:30:25\"},"+ "{\"hospitalNo\": \"00000001\",\"productName\":\"生血宁片\",\"standard\":\"0.15mg片\",\"price\":\"2.5\",\"applyNum\":\"2\",\"totalMoney\":\"5\",\"applyLab\":\"01病区\",\"provideLab\":\"药房\",\"patientName\":\"范子毅\",\"applyDate\":\"2011-10-05 0:30:25\"}"+ "]"+"}}";}return jsonstr;}}

更多相关文章

  1. mybatisplus的坑 insert标签insert into select无参数问题的解决
  2. python起点网月票榜字体反爬案例
  3. android:allowBackup="true"
  4. android升级数据库(Sqlite)简单示例
  5. android通用JSON解析
  6. Android(安卓)MediaMuxer混合音频和视频
  7. Android(安卓)Room 数据库
  8. android 数据保存与提取
  9. android数据库操作

随机推荐

  1. Android更新至2.3.6 改进语音搜索
  2. Android Studio 中使用Lambda
  3. 你的习惯?
  4. 您有一份AndroidX升级指南未领取
  5. 给App启用MultiDex功能
  6. 为什么要学习 Markdown?究竟有什么用?
  7. [Android]将一个视窗(windows)盖在整个Ap
  8. Android–带有动态库、静态库、Jar包的ma
  9. k哥的android开发笔记(更新至2012.05.03)
  10. android 使用GridView实现Gallery的效果,