With an array in JSON format, you can directly access the variable names.
If you are creating this JSON from a String, then @Mike is right, you must parse the JSON first. I was under the assumption that you had JSON returned from a server POST.
var animals_json = '[{"animal":"dog", "sound": "bark"}, {"animal":"cat", "sound": "meow"}]';
var animals_parsed = $.parseJSON(animals_json);
$.each(animals_parsed, function (i, elem) {
console.log(elem.animal + " makes a " + elem.sound);
});
If your JSON is returned from a server side, from say, a PHP page, then you can use it without parsing:
// SERVER SIDE
<?php
//... create JSON
$animals = array(
array('animal' => 'dog', 'sound' => 'bark'),
array('animal' => 'cat', 'sound' => 'meow')
);
?>
// CLIENT SIDE
<html>
<script>
// RETURN FROM PHP PAGE ECHO VIA AJAX PERHAPS //
var animals = <?php echo json_encode($animals) ?>;
$.each(animals, function (i, elem) {
console.log(elem.animal + " makes a " + elem.sound);
});
</script>
</html>