JQuery gets data not accessible as object

advertisements

I get this result from a jQuery GET request, but it isn't seen as an object.

[{
    "amount": "19323",
    "image_tag_id": "1",
    "language_iso": "en",
    "image_tag": "bla",
    "image_content_id": "1",
    "image_id": "1",
    "last_change": "2010-08-18 09:46:53",
    "description": "bla presented by a hairy fly",
    "title": "bla_presented_by_a_hairy_fly",
    "alt_text": "bla presented by a hairy fly"
}]

This is the result I get. I need the amount to be shown on the page. But now if I would get it as an 'imagecount' result and ask an imagecount.amount or imagecount[0].amount it is undefined.

echo json_encode($results); //gives the results

 $.get('/file.php', imageSearchData, function(imagecount) {
   $('.imageAmount').html(imagecount[0].amount);
 });

Call to the file.


The normal $.get, gets a json string. Try using $.getJSON where it already parses the json object.

 $.getJSON('/file.php', imageSearchData, function(imagecount) {
   $('.imageAmount').html(imagecount[0].amount);
 });