11 – Introduction to JSON, JSON vs XML, JSONObjects & JsonArrays – Android Studio



In this tutorial we will understand what is JSON, what’s its structure and what is the difference between JsonObjects and JsonArrays. Later we will see how JSON is better and simpler than XML.

In this tutorial we will also understand how to use HttpUrlConnection class and its methods to make a connection to the server and get a json response.

Watch all videos of this series:

Complete Source code link:

23 Replies to “11 – Introduction to JSON, JSON vs XML, JSONObjects & JsonArrays – Android Studio”

  1. Shay Elbaz

    //MY EASY HOW TO PARSE JSON BEGINNERS STEP BY STEP SOLUTION:
    //STEP 1:
    //COPY THIS TO YOUR CLASS:

    //HERE YOU ADD THE API ADDRESS THAT GIVES YOU A JSON OUTPUT TEXT
    String url = "http://www.floatrates.com/daily/usd.json";

    //HERE YOU CREATE A JSON OBJECT
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
    (Request.Method.GET, url, null, new Response.Listener<JSONObject>() {

    @Override
    public void onResponse(JSONObject response) {
    //HERE YOU HOLD THE JSON ON THE OBJECT "res" AS STRING
    String res = response.toString();
    try {
    //HERE YOU HOLD THE "res" AS JSONOBJECT
    JSONObject obj = new JSONObject(res);
    //HERE YOU FOCUS ON THE "php" SECTION IN THE TEXT JSON FILE
    JSONObject php = obj.getJSONObject("php");
    //HERE YOU FOCUS ON THE "rate"
    String rate = php.getString("rate");
    //HERE YOU PARSE TO DOUBLE
    USD2PHP = Double.parseDouble(rate);
    } catch (JSONException e) {
    e.printStackTrace();
    }

    }
    }, new Response.ErrorListener() {

    @Override
    public void onErrorResponse(VolleyError error) {

    }
    });
    //Access the RequestQueue through your singleton class.
    RequestQueue queue1 = Volley.newRequestQueue(this);
    queue1.add(jsonObjectRequest);

    //STEP 2
    //GO TO THE LIBRARIES ON THE LEFT AND FIND build.gradle
    //Gradle Scripts–>build.gradle (Module: app)
    //FIND "dependencies" AND COPY THIS LINE:
    //compile 'com.android.volley:volley:1.1.0'
    //IT SHOULD BE LOOK LIKE THIS AT THE END:
    dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    compile 'com.android.volley:volley:1.1.0'
    }

    //STEP 3
    //CONNECT TO THE INTERNET
    //GO TO manifests –> AndroidManifext.xml
    //COPY THIS LINE
    // <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    //PASTE IT LIKE THIS:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="meshay.jaxbot.coinexchange_1">

    <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity android:name=".MainActivity">

    <intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>

    </application>
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    </manifest>

    //DONE!

  2. Ash B

    Great tutorial! Simple and easy to understand. I finally had a clear understanding of JSON.
    But the audio is poor.
    If you can reupload these tutorials with a better audio, it would be better for those who are new to your videos.

  3. Wendy Nguyen

    Thanks maaaaan <3 <3 <3 I'll watch all your ads LOL You're super informative, your steps are clear and well explained, and this series is going to make my first exploration into app making more interesting and manageable than all the google searches combined. This thanks is also for videos 12 and 13 <3

  4. Rey Robert Castro

    Hi buddy! I just wanna say that you're videos have been helping me a lot. But I just wanna ask about change the gradle to 22.1 . .I tried to change it but there was an error "The support library should not use different versions (22) . . ." I don't know how to fix it? . .what does the error mean? THanks for your reply.

  5. Mauricio Rossi Photography

    Very well explained… nice tutorial… im trying to parse a WordPress site for my App… and cant understand how to parse it becouse y have this structure

    [
    {
    "id": 229,
    "date": "2016-04-08T20:42:30",
    "date_gmt": "2016-04-08T23:42:30",
    "guid": {
    "rendered": "THE LINK"
    },
    "modified": "2016-04-09T00:52:21",
    "modified_gmt": "2016-04-09T03:52:21",
    "slug": "THE SLUG",
    "type": "post",
    "link": "http://THE SITE",
    ==>"title": {
    "rendered": "TITLE"
    },
    ==>"content": {
    "rendered: "THE CONTENT "
    ]

    How do i parse the title and content of the post?… its objects inside objects?

Leave a Reply

Your email address will not be published. Required fields are marked *