Json Object
Wed Jun 21 2023 21:15:41 GMT+0000 (Coordinated Universal Time)
package Api.request; import org.json.JSONObject; import com.mashape.unirest.http.exceptions.UnirestException; public class FieldsJson { public static void main(String[] args) throws UnirestException { FieldsJson fieldJson = new FieldsJson(); //String jsonTest = jsonString.jsonTest(); Request request = new Request(); String json = request.getJsonTicket(70888); System.out.println(json); System.out.print(fieldJson.getID(json)+ " " ); System.out.println(fieldJson.get_status_code(json));// 2000 - 4000 //System.out.println(jsonString.get_status(json)); // success - failed } public Integer getID (String json) { // JSONObject JSONObject jsonObject = new JSONObject(json); JSONObject request = jsonObject.getJSONObject("request"); // request int id = request.getInt("id"); return id; } public Integer get_status_code (String json) { // JSONObject JSONObject jsonObject = new JSONObject(json); JSONObject response_status = jsonObject.getJSONObject("response_status"); // status_code int status_code = response_status.getInt("status_code"); return status_code; } public String get_status (String json) { // JSONObject JSONObject jsonObject = new JSONObject(json); JSONObject response_status = jsonObject.getJSONObject("response_status"); // status String status = response_status.getString("status"); return status; } public Integer get_All (String json) { //FieldsJson gfj = new FieldsJson(); //String json = gfj.jsonTest(); // JSONObject JSONObject jsonObject = new JSONObject(json); JSONObject request = jsonObject.getJSONObject("request"); JSONObject response_status = jsonObject.getJSONObject("response_status"); // // request int id = request.getInt("id"); // response_status int status_code = response_status.getInt("status_code"); String status = response_status.getString("status"); System.out.println("id:"+ id + " response_status: " + status_code + " Status:"+ status); return id; } }
Comments