设置jsonobject实体对象
JSONObject ClinetKey = new JSONObject();
try {
//向JSONobject中放入数据,其实在这里放入数据的顺序可能在得到的JSON数据每个数据的顺序是不一样的,但是JSON对顺序没有要求
ClinetKey.put("dev_sn", string);
ClinetKey.put("os_type", os);
ClinetKey.put("os_version", android);
ClinetKey.put("app_version", version);
} catch (JSONException e) {
e.printStackTrace();
}
JSONObject Authorization = new JSONObject();
try {
Authorization.put("type", 1);
Authorization.put("client_info", ClinetKey);
} catch (JSONException e) {
e.printStackTrace();
}
Log.i("test", Authorization.toString());
String content = String.valueOf(Authorization);
得到的JSON数据:{“type”:1,“client_info:”{“dev_sn:”“string的值”,“os_type:”:“os的值”…..} }