Take the 2-minute tour ×

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),



    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,
share|improve this question
Is this in IE's debugging tools? –  pimvdb Oct 1 '11 at 14:52
Chrome's Console –  Tom Oct 1 '11 at 14:56
Are you joining the array or something? You'll only get this when converting an object into a string. –  pimvdb Oct 1 '11 at 14:59
add comment

3 Answers

up vote 1 down vote accepted

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 = [];
    var tmp = new Ext.Component({
        id: 'page'+i,
        cls: 'page',
share|improve this answer
Great idea, but two issues: 1. The numberofpages is returning a character count (one example is it is creating 75 cards, not 5 for the images). 2. this.record.data.images[i].imageurl is not returning anything but an empty card. Maybe I'm not firing imageurl somehow? –  Tom Oct 1 '11 at 15:20
Can you please post a proper JSON output. The one you posed above is broken :| –  Rifat Oct 1 '11 at 15:22
My json is very long, but here is a new pastbin with only one post, I think its correct: pastie.org/2622399 –  Tom Oct 1 '11 at 15:28
To answer your update question, my controller feeds the data into the container using this: var singlePost = App.views.postView.add({ xtype: 'postsingleview', record: options.record }); and I pull the data out using the default feature: defaults: { data:this.record.data } –  Tom Oct 1 '11 at 15:49
I think it is in the right direction, but now no cards appear and I don't think this.record.data.images is calling the correct data. console.log(this.record.data.images); only yields [object Object],[object Object],[object Object],[object Object],[object Object] –  Tom Oct 1 '11 at 17:08
show 4 more comments

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.

share|improve this answer
So what you are saying is I need to decode them on Sencha touches end? I didn't have to do that with any of the other data, why with this? Just to clarify its returning a string of [object object], rather than an array where I can see the URL's coming through. If I do a record.data.length it gives me a character count instead of saying, for example, 5 images in the array. –  Tom Oct 1 '11 at 14:57
It's not returning a string of "[object Object]", it's returning an object which looks like that when converted to a string. –  Ignacio Vazquez-Abrams Oct 1 '11 at 15:01
So I'm missing something then. I need to decode the json objects when requesting them to appear in the application? Shouldn't I be able to open the console and look at my log and see the objects values? –  Tom Oct 1 '11 at 15:02
1) They're already decoded. 2) Why do you believe that JavaScript works that way? –  Ignacio Vazquez-Abrams Oct 1 '11 at 15:03
1. Ok, 2. Ignorance to be honest. What I'm looking to do is get the imageurl out of the object with sencha. I'll update my question with the sencha code that I'm using to get the images/imageurl. Thanks for your help and understanding –  Tom Oct 1 '11 at 15:06
show 6 more comments

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.

share|improve this answer
add comment

Your Answer


