Lijoyx Posted November 2, 2007 Share Posted November 2, 2007 hai friends, i have adoubt in json i want to use a for loop to add a specific item to a json object. it should be something like below user={{"name":"lop"},{"name":"lop"}} i want to add more {"name":"value"} using a for loop. if u know this just show me and let others know Link to comment https://forums.phpfreaks.com/topic/75748-solved-json/ Share on other sites More sharing options...
emehrkay Posted November 2, 2007 Share Posted November 2, 2007 JSON is a javascript object. each one of your sub-objects ({"name": "lop"}) must have an unique key associated with them. json = {"first": {"name": "lop"}, "second": {"name": "lop"}...}; to add to any object, you can simply use dot notation json.third = {'third name': 'third lop'}; Link to comment https://forums.phpfreaks.com/topic/75748-solved-json/#findComment-383517 Share on other sites More sharing options...
emehrkay Posted November 2, 2007 Share Posted November 2, 2007 see this example json = {'name': 'Lijoyx'}; json.a = function(){ alert(this.name); }; json.a(); Link to comment https://forums.phpfreaks.com/topic/75748-solved-json/#findComment-383521 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.