simple example of using json

Assuming that this array is the return value of ajax and already been evaluated to json.
This is the link on how to do it http://dreamluverz.com/2007/12/12/ajax-and-json/

The {} and [] symbolizes for array

“key” : “value” => ‘:’ colon separates the key and value

var a = {"ids" :[
{"id" : "1", "name" :
["a", "b"]
},
{"id" : "2", "name" :
[ "ab"]
}
]}

for(var d=0; d < a.ids.length; d++){
alert(a.ids[d].id);
for(var p=0; p < a.ids[d].name.length; p++){
alert(a.ids[d].name[p]);
}
}

Imagine that array in this way using php:

$ids[0]['id'] = 1;
$ids[0]['name'] = array(“a”, “b”);

$ids[1]['id'] = 2;
$ids[1]['name'] = array(“a”);








This entry was posted in ajax, javascript and tagged , , , , , , . Bookmark the permalink.

2 Responses to simple example of using json

  1. r00tk1d says:

    w00t

    couldn't you get more ads to this page?
    its even more ads then article lol

  2. r00tk1d says:

    w00t

    couldn't you get more ads to this page?
    its even more ads then article lol

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>