android JSON解析之JSONObject

compile group: 'com.alibaba', name: 'fastjson', version: '1.2.47'


 public void queryaa(){
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    // 定义okhttp
                    OkHttpClient okHttpClient_post_kv = new OkHttpClient();
                    // 定义请求体
                    // 执行okhttp
                    RequestBody body = new FormBody.Builder()
                            .add("rfid", Erfid.getText().toString().trim())//添加参数体
                            .build();
                    Request request = new Request.Builder()
                            .post(body) //请求参数
                            .url(DATABASE_URL+SQUERY_URL)
                            .build();
                    Response response = okHttpClient_post_kv.newCall(request).execute();
                    // System.out.println(response.body().string());
                    String res =response.body().string();
                    ReturnObject returnObject = JSON.parseObject(res, new TypeReference() {});
                    Sbox=returnObject.getMap().getBox_no();
                    Sname=returnObject.getMap().getVeg_name();
                    Sorigin=returnObject.getMap().getVeg_origin();

                    Snum=returnObject.getMap().getVeg_num();
                    Stime=returnObject.getMap().getVeg_pick_time();
                    Sckuname=returnObject.getMap().getSite_name();
                    Scshiname=returnObject.getMap().getMarket_name();
                    Sckutime=returnObject.getMap().getSite_time();
                    Scshitime=returnObject.getMap().getMarket_time();
                    REtext=returnObject.getMsg();
                    Message msg = Message.obtain();
                    msg.what = 011;
                    Handler.sendMessage(msg);
                   /* JSONObject jsonObject = new JSONObject(response.body().string());

                    System.out.println("******code********"+ jsonObject.getInt("code"));
                   if(jsonObject.getInt("code")==0){
                        REtext=jsonObject.getString("msg");
                        Message msg = Message.obtain();
                        msg.what = 013;
                        Handler.sendMessage(msg);
                    }
                    System.out.println("******ReturnObject********"+ jsonObject.optJSONObject("ReturnObject"));
                    if( jsonObject.optJSONObject("ReturnObject")!=null){
                        JSONObject data = jsonObject.optJSONObject("ReturnObject");
                        if(data.getString("box_no")!=null){
                            Sbox=data.getString("box_no");
                            System.out.println("******box_no********"+ data.getString("box_no"));
                        }
                        if(data.getString("veg_name")!=null){
                            Sname=data.getString("veg_name");
                            System.out.println("******veg_name********"+ data.getString("veg_name"));
                        }
                        if(data.getString("veg_origin")!=null){
                            Sorigin=data.getString("veg_origin");
                            System.out.println("******veg_origin********"+ data.getString("veg_origin"));
                        }
                        if(data.getString("veg_num")!=null){
                            Snum=data.getString("veg_num");
                        }
                        if(data.getString("veg_pick_time")!=null){
                            Stime=data.getString("veg_pick_time");
                        }
                        if(data.getString("site_name")!=null){
                            Sckuname=data.getString("site_name");
                        }
                        if(data.getString("market_name")!=null){
                            Scshiname=data.getString("market_name");
                        }
                        if(data.getString("site_time")!=null){
                            Sckutime=data.getString("site_time");
                        }
                        if(data.getString("market_time")!=null){
                            Scshitime=data.getString("market_time");
                        }
                        REtext=jsonObject.getString("msg");
                        Message msg = Message.obtain();
                        msg.what = 011;
                        Handler.sendMessage(msg);
                    }*/
                } catch (Error e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

  

public class ReturnObject {
    public int code;
    public Veg map;
    public String msg;


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public Veg getMap() {
        return map;
    }

    public void setMap(Veg map) {
        this.map = map;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}

  

public class Veg {
    public int id;
    public String box_no;
    public String veg_name;
    public String veg_origin;
    public String veg_pick_time;
    public String veg_num;
    public String site_time;
    public String site_name;
    public String market_time;
    public String market_name;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getBox_no() {
        return box_no;
    }

    public void setBox_no(String box_no) {
        this.box_no = box_no;
    }

    public String getVeg_name() {
        return veg_name;
    }

    public void setVeg_name(String veg_name) {
        this.veg_name = veg_name;
    }

    public String getVeg_origin() {
        return veg_origin;
    }

    public void setVeg_origin(String veg_origin) {
        this.veg_origin = veg_origin;
    }

    public String getVeg_pick_time() {
        return veg_pick_time;
    }

    public void setVeg_pick_time(String veg_pick_time) {
        this.veg_pick_time = veg_pick_time;
    }

    public String getVeg_num() {
        return veg_num;
    }

    public void setVeg_num(String veg_num) {
        this.veg_num = veg_num;
    }

    public String getSite_time() {
        return site_time;
    }

    public void setSite_time(String site_time) {
        this.site_time = site_time;
    }

    public String getSite_name() {
        return site_name;
    }

    public void setSite_name(String site_name) {
        this.site_name = site_name;
    }

    public String getMarket_time() {
        return market_time;
    }

    public void setMarket_time(String market_time) {
        this.market_time = market_time;
    }

    public String getMarket_name() {
        return market_name;
    }

    public void setMarket_name(String market_name) {
        this.market_name = market_name;
    }
}

  

你可能感兴趣的:(android JSON解析之JSONObject)