How to use JSON with Jquery?

To get JSON with jQuery, just use jQuery.getJSON(). Alternatively, you can use any other AJAX tool and then just eval() the json to get a javascript object.

To loop through an array, I usually use jQuery.each():

var recordList = yourMethodToGetRecordListWithAjax();

jQuery.each(recordList, function()
{
    alert(this.Name); // For example
});

1) in the php script:

$return["foo"]  = "bar";
$return["blah"] = "bleg";
print json_encode($return);

2) in the javascript:

$.ajax({
  type: "POST",
  url: URL,
  cache: false,
  data: values,
  dataType: 'json',
  success: function(json) {
    var foo = json.foo;
    if (json.blah == "bleg") {
      // do stuff 
    }
  } // end success function
}); // end ajax call