Android AsyncTask with JSON Parsing – Example

Json

You may also like...

  • Alex

    Thank you very much. You helped me allot.

    • http://128.199.224.11/ Raj Amal

      Thank you, Keep visiting :)

  • ikki

    when you mean that we need a json folder in the root server, are you refering where is the android-sdks??? adb command?
    Thanks for your replay

    • http://128.199.224.11/ Raj Amal

      Yes you need. Or change the URL to “http://api.learn2crack.com/android/json/” to test.

  • shouba

    What if my JSON Array does not have a name “user”, How to do that ?

    • http://128.199.224.11/ Raj Amal

      Rename “user” to the name you used in your array.

  • Zahid
  • Khairul

    What if the content has more layers of array in it. How do i extract them out.

    {
    “directions”: [
    {
    "features": [
    {
    "attributes" : {
    "text":
    }
    }
    ]
    }
    ]
    }

    Tried doing this way, but there’s no output in my textview.

    directions = json.getJSONArray(TAG_DIRECTIONS);
    JSONObject c = directions.getJSONObject(0);

    JSONObject features = c.getJSONObject(TAG_FEATURES);
    String attributes = features.getString(TAG_ATTRIBUTES);

  • Benny Margalit

    thanks a lot.
    in the example i can aslo define JSONParse as just return JSONObject and 2 other parameters can be made Void

    • http://128.199.224.11/ Raj Amal

      Yes you can use void

  • Arijit Chakraborty

    Really helped me a lot man :-D…u rock m/

  • tj

    can you give some examples for http post,like login…can register the username and password..

  • Muhammad Umair

    Sir its giving me error tat string cannot be converted to JSONARRAY

    • http://www.learn2crack.com/ Raj Amal

      Post your JSON format.

      • Sunil

        Raj Sir.. It is giving me error Null pointer exception. I have tried alot. Please tell me what to do ? Thanks in Advance.

        Code is same as u have given. Please help me.

  • Allah

    Just a little mistake there

    sb.append(line + “n”);

    It should be a “n”

  • Gopala Palanee

    i want to pass those data to the JSONParser

    ArrayList nameValuePairs = new ArrayList();
    nameValuePairs.add(new BasicNameValuePair(“usernamejoiner”, username));
    nameValuePairs.add(new BasicNameValuePair(“departuretime”, departure_t));
    nameValuePairs.add(new BasicNameValuePair(“endtime”, end_t));
    nameValuePairs.add(new BasicNameValuePair(“departureaddress”, deparure_a));
    nameValuePairs.add(new BasicNameValuePair(“destinationaddress”, destination_a));
    nameValuePairs.add(new BasicNameValuePair(“date”, date_t));

    the data shall be obtain from sharedpreferences

    base on the data send the url , the php file will send a valid form of json data
    how to do that ? a little help please …

    • http://www.learn2crack.com/ Raj Amal

      Add this to your JSON Parser and add parameter to the function.
      httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));