Cybercrux

Everything is achievable through technology

Json

Json Add Edit Update Events

var sitePersonel = {};
var employees = []
sitePersonel.employees = employees;
for(var i=1;i<=10;i++)
{
var firstName = "John";
var lastName = "Smith";
var employee = {
"firstName": firstName+i,
"lastName": lastName+i
}
sitePersonel.employees.push(employee);
}
var manager = "Jane Doe";
sitePersonel.employees[0].manager = manager;//Add New Attribute
console.log(sitePersonel);// Json Object
console.log(JSON.stringify(sitePersonel));//Json String
//console.log(JSON.parse(JSON.stringify(sitePersonel)));//Json String to Object
// Select Node One method
$.each(sitePersonel.employees, function(i, v) {
if (v.firstName == "John5") {
console.log(v.lastName);
return;
}
});

Find in Json Key value Pair

option 1
$.each(result[0], function(key, value){
console.log(key, value);
});
option 2
var test ={"data":[{"label":"facebook","abc":1},{"label":"twitter","abc":1}],"total":2,"isWorking":true};
var index = test.data.map(function(d) { return d['label']; }).indexOf('facebook')

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s