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;
}
2
  • 2
    This is the best example to download and parse JSON. check this: stackoverflow.com/questions/13196234/… Commented May 14, 2016 at 13:52
  • Log.d("Response: ", "> " + obj.getJSONObject("query").getString("pengirim")); do this. I think your code is ok Commented May 14, 2016 at 14:02

2 Answers 2

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);
Sign up to request clarification or add additional context in comments.

Comments

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.