I'm attempting to call values from a JSON associative array. I'm finding difficulties as my object is wrapped in "[ ]". For instance:
var scifi = [
{
"Show":"TNG",
"Ship":"Enterprise",
"Captain":"Picard"
},
{
"Show":"BSG",
"Ship":"Galactica",
"Captain":"Adama"
},
{
"Show":"Firefly",
"Ship":"Serenity",
"Captain":"Reynolds"
}
]
So for instance before I was assuming that in order to call out Adama I would use the command
scifi.Captain[1]
However that seems to be outright failing. Any advice is appreciated.
EDIT-----------
I'm thinking part of the problem may be in the ajax I'm using.
$.ajax({
url: './php/scifishows.php',
type: 'POST',
//dataType: 'json',
data:
{
show: fav_show
},
success: function(output)
{
alert(output[1].Captain);
}
});
And this is the php code that causes the brackets, which loops through the mysql results and and places them in a single object. This is of course called by the above ajax.
$all = array();
while( ($row = mysql_fetch_assoc($result)) ) {
$all[] = $row;
}