Json返回[object object]而不是array [英] Json Returning [object object] instead of array
问题描述
我将json数据输入Sencha touch应用程序。这是json:
I have json data being fed into a Sencha touch app. Here's the json:
http://pastie.org/2622260 - (当然是为一个例子而修改)
http://pastie.org/2622260 - (modified for an example, of course)
当我返回images和console.log时,它会返回以下内容:
When I return the "images" and console.log it, it returns the following:
images: "[object Object],[object Object],[object Object],[object Object],[object Object]"
而不是网址。
我的json编码器看起来像这样(我将数据从Wordpress网站中拉出来):
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){
$count++;
$imgurl[] = array(
'count'=>$count,
'imageurl'=>get('photo_image_file', $count, 1, false, $post->ID),
);
}
$json['posts'][] = array(
'id'=>$post->ID,
'title'=>$post->post_title,
'body'=>apply_filters('the_excerpt', $post->post_content),
'date'=>$post->post_date,
'user'=>get_userdata($post->post_author)->user_firstname,
'images'=>$imgurl
);
}
}
header('Content-type: application/json');
echo json_encode($json);
exit();
我正在寻找的是返回图片网址数组,而不是[我目前得到的对象对象。
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.
编辑:这是我用来尝试拉出图像的sencha代码:
Here is the sencha code I'm using to try to pull the imageurl out:
console.log(this.record.data);
console.log(this.record.data.images);
console.log(this.record.data.images.length);
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>',
//html:'test',
}));
}
// Create the carousel
this.carousel = new Ext.Carousel({
id: 'carousel',
title:'Gallery',
iconCls:'photos2',
defaults: {
cls: 'card'
},
items: 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>'
});
tmp.update(this.record.data[i].images);
pages.push(tmp);
}
这篇关于Json返回[object object]而不是array的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!