Android tutorial - Android JSON Parser - android app development - android studio - android development tutorial
Learn android - android tutorial - Android json parser - android examples - android programs
- JSON stands for JavaScript Object Notation.
- It is an independent data exchange format and is the best alternative for XML.
- This chapter explains how to parse the JSON file and extract necessary information from it.
- Android provides four different classes to manipulate JSON data. These classes are JSONArray,JSONObject,JSONStringer and JSONTokenizer.
- JSON (Javascript Object Notation) is a programming language.
- It is minimal, textual, and a subset of JavaScript. It is an alternative to XML.
- Android provides support to parse the JSON object and array.
Advantage of JSON over XML
- JSON is faster and easier than xml for AJAX applications.
- Unlike XML, it is shorter and quicker to read and write.
- It uses array.
json object
- A JSON object contains key/value pairs like map.
- The keys are strings and the values are the JSON types.
- Keys and values are separated by comma.
- The { (curly brace) represents the json object.
json array
- The [ (square bracket) represents the json array.
- Let's take another example of json array.
Example of android JSON parsing
activity_main.xml
- Drag the one textview from the pallete. Now the activity_main.xml file will look like this:
- File: activity_main.xml
Activity class
- Let's write the code to parse the xml using dom parser.
- File: MainActivity.java
Output:
Parsing JSONArray in Android
Learn android - android tutorial - Json parser - android examples - android programs
- By the help of JSONArray class, you can parse the JSONArray containing the JSON Objects. Let's see the simple example to parse the json array.
- File: MainActivity.java