0

I am developing an app in which i want to fetch some data which is in json format but i don't know how to fetch. Please guide me.

Json data:-

{
    "title":"title",
        "description":"description",
        "icon":{
    "url":"<image-url>",
            "aspectRatio":1,
            "height":75,
            "width":75
},
    "screenshots":{
    "url":"<image-url>",
            "aspectRatio":1.91,
            "height":627,
            "width":1200
},
    "landingURL":"LandingUrl",
        "cta":"cta",
        "rating":"rating"
}
Sagar Gangawane
  • 1,985
  • 1
  • 12
  • 22
Ravi
  • 117
  • 1
  • 8

3 Answers3

1

Put your response in Jsonobject.

 JSONObject jsonObject = new JSONObject(response);

and parse your json.

Jd Prajapati
  • 1,953
  • 13
  • 24
0
JSONObject jsonObject = new JSONObject(data);
String title = jsonObject.getString("title");
String description = jsonObject.getString("description");
JSONObject iconObject = jsonObject.JSONObject("icon");

This is how you can parse your json data. but it is even better to use Gson.

Junaid Hafeez
  • 1,618
  • 1
  • 16
  • 25
0

Checkout the following code:

try {
     JSONObject jsonObject = new JSONObject(response);
     String title = jsonObject.getString("title");
     String description = jsonObject.getString("description");
     JSONObject jObj = new JSONObject("icon");
         if(jObj.has("url")) {
            String url = jObj.getString("url");
            int aspectRatio = jObj.getInt("aspectRatio");
            int height = jObj.getInt("height");
            int width = jObj.getInt("width");
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
tahsinRupam
  • 6,325
  • 1
  • 18
  • 34