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 Quote Link to comment 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'}; Quote Link to comment 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(); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.