android 用JSON 解析数据接口方法

接口获取下来的数据为

{"status":200,"message":"查询成功","data":{"id":32,"user_id":null,"user_code":null,"user_pass":null,"meeting_id":"1","meeting_pass":null,"config_param_ip":"11.1.1.70","port":"6501","web_config_param_ip":"11.1.1.70","web_port":"6501","unit_code":null,"create_time":null,"update_time":null,"status":0,"userCode":"video1","userPass":"video1","meetingId":"1","meetingPass":"","apiPort":"13000","username":"admin","password":"123456","updateTime":"2021-11-08 17:45:29"}}

使用方法

try {

    JSONObject jsonObject = new JSONObject(outstring);

    int resultCode = jsonObject.getInt("status");

    if (resultCode == 200) {

        JSONObject obj = jsonObject.getJSONObject("data");

        IP = obj.getString("config_param_ip");

        port = obj.getString("web_port");

        username = obj.getString("userCode");

        password = obj.getString("userPass");

        roomID = Integer.parseInt(obj.getString("meetingId"));

        roomPassword = obj.getString("password");

    } else {

        ToastUtils.showShort("查询失败");

    }

    goVideo();

} catch (Exception e) {

    e.printStackTrace();

}

你可能感兴趣的:(android 用JSON 解析数据接口方法)