SubscribeSubscribe with Androidlift to get new post on mail.

Android JSON Object and Array Parsing

Android JSON Object and Array Parsing

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition – December 1999.

What is JSON?

  • JSON stands for JavaScript Object Notation
  • JSON is a lightweight data-interchange format
  • JSON is language independent *
  • JSON is “self-describing” and easy to understand

Note   JSON uses JavaScript syntax, but the JSON format is text only, just like XML.
Text can be read and used as a data format by any programming language.

Advantages of JSON over XML –

  • JSON is a valid subset of JavaScript, Python, and YAML
  • JSON parsing is generally faster than XML parsing.
  • JSON is a more compact format, meaning it weighs far less on the wire than the more verbose XML.
  • JSON is easier to work with in some languages (such as javascript, python, and php)
  • Formatted JSON is generally easier to read than formatted XML.
  • JSON specifies how to represent complex datatypes, there is no single best way to represent a data structure in XML.

json object

JSON objects are written inside curly braces.

Just like JavaScript, JSON objects can contain multiple name/values pairs:

Example :

JSON Arrays

JSON arrays are written inside square brackets.

Just like JavaScript, a JSON array can contain multiple objects:

Example :

In the example above, the object “employees” is an array containing three objects. Each object is a record of a person (with a first name and a last name).

 

Example of android JSON parsing ( JsonParsing )

Output :

android JSON parsing
android JSON parsing

app.gradle

colors.xml

activity_main.xml

MainActivity.java

Please do subscribe to androidlift.info for more updates and share our posts…!

Good Luck…!

 

(65)