-5

I stuck in this problem how to parse json in from a url in android studio below is my json structure tried all other methods did'nt work for me

url : http://api.ipstack.com/109.94.137.130?access_key=e9e5de2c993dc6652ed45c3f9dc53daf

{
   "ip":"109.94.137.130",
   "type":"ipv4",
   "continent_code":"EU",
   "continent_name":"Europe",
   "country_code":"GB",
   "country_name":"United Kingdom",
   "region_code":"ENG",
   "region_name":"England",
   "city":"Bedford",
   "zip":"MK42",
   "latitude":52.1073,
   "longitude":-0.4649,
   "location":{
      "geoname_id":2656046,
      "capital":"London",
      "languages":[
         {
            "code":"en",
            "name":"English",
            "native":"English"
         }
      ],
      "country_flag":"http:\/\/assets.ipstack.com\/flags\/gb.svg",
      "country_flag_emoji":"\ud83c\uddec\ud83c\udde7",
      "country_flag_emoji_unicode":"U+1F1EC U+1F1E7",
      "calling_code":"44",
      "is_eu":true
   }
}

please help regarding this issue. thanks in advance.

Jay Dangar
  • 3,271
  • 1
  • 16
  • 35
Thomas
  • 35
  • 2
  • 8

2 Answers2

1

Getting the data from API using retrofit or volley. Sample Retrofit Implementation

Use GSON library for parsing gson. As, it's easy to implement it.

Parsing code snippet is:

ModelClass sInfo_parse = new Gson().fromJson(getURLJson, ModelClass.class);
Ali Azaz Alam
  • 1,782
  • 1
  • 16
  • 27
-2

Add volley in your gradle file from here. Now add below line in your java file.

RequestQueue queue = Volley.newRequestQueue(ChangePasswordActivity.this);

Now call make StringRequest constructor in onCreate method like below method.

        String Url = your url

                    Log.d(TAG, Url);

                    StringRequest stringRequest = new StringRequest(Request.Method.GET, Url,
                            new Response.Listener<String>() {
                                @Override
                                public void onResponse(String response) {
                                    Log.d("response", response);

// here you can find your all json value.
                                }
                            },
                            new Response.ErrorListener() {
                                @Override
                                public void onErrorResponse(VolleyError error) {
                                    error.printStackTrace();
                                }
                            }
                    );

                    queue.add(stringRequest);
                }
BlackBlind
  • 772
  • 9
  • 26
  • While this code snippet may answer the question, please add some explanation as to why it does. This will make for better answers and help future users understand how the problem was solved. – Andrew Mar 15 '19 at 09:44
  • can u help me to retrieve at least one value from the json structure – Thomas Mar 25 '19 at 11:46
  • which value do you want to retrieve according to you json file – BlackBlind Mar 25 '19 at 12:13