Array in JSON


Prev Tutorial Next Tutorial

Array in JSON

In JSON array are declare inside square brackets. Some like JavaScript, a JSON array can contain multiple objects.

Example

"employees":[
    {"firstName":"Komal", "lastName":"Pandit"}, 
    {"firstName":"Ajay", "lastName":"Jain"}, 
    {"firstName":"Hitesh","lastName":"Kumar"}
]

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

Declare array in JSon

Example

var employees = [
    {"firstName":"Komal", "lastName":"Pandit"}, 
    {"firstName":"Ajay", "lastName":"Jain"}, 
    {"firstName":"Hitesh","lastName":"Kumar"}
];

Access Data for array in JSON

First way

employees[0].firstName + " " + employees[0].lastName;
// returns Komal Pandit

Second Way

employees[0]["firstName"] + " " + employees[0]["lastName"];
// returns Komal Pandit

Modify Data of array in JSON

First way

employees[0].firstName = "Kajol";

Prev Tutorial Next Tutorial



Download Projects

Advertisements

FREE Online Google Play APK Downloader

Buy APP Installs, Buy 100% Genuine Installs