Json Returning [object object] instead of array

I have json data being fed into a Sencha touch app. Here's the json:

http://pastie.org/2622260 - (modified for an example, of course)

When I return the "images" and console.log it, it returns the following:

images: "[object Object],[object Object],[object Object],[object Object],[object Object]"

Rather than the URLs.

My json encoder looks like this (I'm pulling the data out of a Wordpress site):

 case 'posts':
    foreach(get_posts('numberposts=50&category=') as $post) {

            $count = 0;
            $imgurl = array();
            foreach( get_group('Photo', $post->ID) as $images){
                $imgurl[] = array(
                    'imageurl'=>get('photo_image_file', $count, 1, false, $post->ID),

      $json['posts'][] = array(
        'body'=>apply_filters('the_excerpt', $post->post_content),


    header('Content-type: application/json');

    echo json_encode($json);

What I am looking for it to do is to return the array of image urls, rather than the [object object] that I am currently getting.

EDIT: Here is the sencha code I'm using to try to pull the imageurl out:



    var numberOfPages = this.record.data.images.length;
    // Create pages for the carousel
    var pages = [];
    for (var i=0; i<numberOfPages; i++) {
        pages.push(new Ext.Component({
            id: 'page'+i,
            cls: 'page',
            tpl: '<tpl for=".">{imageurl}</tpl>',

    // Create the carousel
    this.carousel = new Ext.Carousel({
        id: 'carousel',
        defaults: {
            cls: 'card'
        items: pages,



Update: Sorry, for the irrelevant example I had given

Where is your pages[i].update(this.record.data.images); ?

You can try the following -

var numberOfPages = this.record.data.length;
// Create pages for the carousel
var pages = [];
for (var i=0; i<numberOfPages; i++) {
    var tmp = new Ext.Component({
        id: 'page'+i,
        cls: 'page',
        tpl: '<tpl for=".">{imageurl}</tpl>'

Associative arrays in PHP encoded as JSON become objects in JavaScript when decoded. What you're seeing is correct and normal. Access them as you would any other object in JavaScript.


Found the answer, gave it to Rifat because his answer was the springboard.

I had the [object object]'s coming through as a literal string of characters. I wrote a quick test.php outside Sencha touch and was able to get the actual array to work. My first issue was the json itself - It needed to be validated. You guys were all correct and thank you for that clue.

Second, once I got the test.php document working, I realized it had to be within Sencha itself. The nagging feeling that the string of characters had something to do with it sat in my head. Finally, I went to my model and found how I was pulling the images:

{name: "images", type: "string"},

I saw string, and the aha moment hit! This fixed it and gave me my URL's:

{name: "images"},

Can't thank Ignacio and Rifat enough. You guys hung in there with me and got the answer to (eventually) appear. Thanks again, and hope this helps anyone else that may run into a similar issue.


I had a similar issue once, in the javascript backend. Here is an answer for people using JS:

Make sure to stringify your object arrays before sending them:


Unless ofcourse you are ONLY sending JSON, which in that case sending regular JSON should work fine :)


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.