0

I tried the code shown below, but data not showing.

This is the URL from where I'm fetching the JSON Object

http://ibacor.com/api/cek-resi?pengirim=jne&resi=1892297430009

@Override
protected Void doInBackground(Void... arg0) {
    // Creating service handler class instance
    try {
        JSONObject obj = new JSONObject(url);
        obj.getJSONObject("query").getString("pengirim");
        Log.d("Response: ", "> " + obj);
    } catch (Exception e) {
        // TODO: handle exception
    }
    return null;
}
A0__oN
  • 8,740
  • 6
  • 40
  • 61
  • 2
    This is the best example to download and parse JSON. check this: http://stackoverflow.com/questions/13196234/simple-parse-json-from-url-on-android-and-display-in-listview?answertab=active#tab-top – ᴛʜᴇᴘᴀᴛᴇʟ May 14 '16 at 13:52
  • Log.d("Response: ", "> " + obj.getJSONObject("query").getString("pengirim")); do this. I think your code is ok – Masum May 14 '16 at 14:02

2 Answers2

2

You're not assigning the value returned by obj.getJSONObject("query").getString("pengirim"); to anything, and you're logging the JSONObject itself. Try something like this:

String pengirim = obj.getJSONObject("query").getString("pengirim");
Log.d("Response: ", "> " + pengirim);
mgaldieri
  • 143
  • 1
  • 7
0

How can I set the String URL? The URL I'm trying to set is below.

This is working.

String data="data copy paste from url";
JSONObject reader = new JSONObject(data);

But this is not working. Need help on this.

String url="http://ibacor.com/api/cek-resi?pengirim=jne&resi=1892297430009";
JSONObject reader = new JSONObject(url);