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 の読み込みが正常に機能することに注意してください。
誰かが私が間違っていることを教えてもらえますか? 前もって感謝します!