我正在用 php 生成一个 json 文件并将其存储在我的服务器上。这是导出json的代码
/**
* FUNCTIONS TO EXPORT AS JSON
*/
public function expose() {
return array(
'guid' => $this->guid,
'title' => $this->title,
'folder' => $this->folder,
'owner' => $this->owner,
#'pictures' => json_encode(array_values($this->pictures), JSON_FORCE_OBJECT),
'excude' => $this->excude,
'added' => $this->added,
'lastViewed' => $this->lastViewed,
);
#return get_object_vars($this);
}
public function toJSON(){
return json_encode($this->expose(), JSON_FORCE_OBJECT);
}
该文件的内容是这样的:
{"guid":"","title":"Sample Gallery","folder":"sampleGallery","owner":"","excude":true," added":"","lastViewed":" "}
然后在我的 html 文件中,我尝试使用 jquery 加载它,但我无法将对象获取到控制台
$.getJSON('/files/galleries/index/sampleGallery.gallery', function(data) {
console.log(data); // works!
var jsonObj = jQuery.parseJSON(data);
for (key in jsonObj) {
console.log(key+':'+JSON.stringify(jsonObj[key]));
}
});
请注意,json 的加载工作正常!
有人可以告诉我我做错了什么吗?提前致谢!