-4

this is the api response i ma accessing the json object and setting the textview of uuid in text view but nothing happen

please suggest code for accessing json object from api response

{
 "success":true,
 "data {
   "serial_key_id":"75",
   "order_id":"0",
   "product_id":"0",
   "serial_key":"WURYFO",
   "valid_till":null,
   "limit":"0",
   "uuid":"",
   "used":false
   }
}

private void jsonobject() {

    String url = "http://mylocalpay.com/?serial_key_api=1&coupon=WURYFO";
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
            (Request.Method.GET, url, null, new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response) {
                    Log.i("msg", "response" + response);
                    try {
                        JSONObject success = response.getJSONObject("success");
                        JSONObject data = response.getJSONObject("data");
                        String serial_key_id = data.getString("serial_key_id");
                        String order_id = data.getString("order_id");
                        String product_id = data.getString("product_id");
                        String serial_key = data.getString("serial_key");
                        String limit = data.getString("limit");
                        String uuid = data.getString("uuid");
                        boolean used = data.getBoolean("used");
                        JSONObject valid_till = data.getJSONObject("valid_till");
                        textView.setText(uuid);
                        System.out.println(serial_key);


                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }

            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    // TODO: Handle error

                }

            });
}

}

1 Answers1

0

You need to parse this JSON into a java object. You could write your own code to do this (which is a very large undertaking) or you could use Googles GSON library.

GSON GitHub page

You can use this library as so

Gson gson = new Gson();
String jsonInString = "{'serial_key_id' : '75'}";
YourClass yourClass = gson.fromJson(jsonInString, YourClass.class);
Josh
  • 901
  • 8
  • 29