0

我正在使用以下内容将数据从 mysql 转换为 JSON:

$sql = "select img_name from user_gallery_images where user_id=$_SESSION[user_id]";

        $response = array();
        $posts = array();

        $result = $mysqli->query($sql);

        while($row = $result->fetch_array()){

            $file=$row['img_name']; 
            $fileDir = "gallery/$file.jpg";
            $posts[] = array('thumb'=> $fileDir, 'image'=> $fileDir);

        } 

        $response['posts'] = $posts;

        $fp = fopen('/home/public_html/users/'.$settings[username].'/gallery/gallery.json', 'w');
        $jsonData = stripslashes(json_encode($response));
        fwrite($fp, $jsonData);
        fclose($fp);

哪个运作良好并创建例如

{"posts":
[
{"thumb":"gallery/tess1367386438.jpg","image":"gallery/tess1367386438.jpg"},
{"thumb":"gallery/tess1367386538.jpg","image":"gallery/tess1367386538.jpg"}
]
}

但是,我正在使用的 JQuery 插件不会与外部“帖子”容器一起读取它

问题:

如何剥离 JSON 中的外部“帖子”容器以仅生成:

[
{"thumb":"gallery/tess1367386438.jpg","image":"gallery/tess1367386438.jpg"},
{"thumb":"gallery/tess1367386538.jpg","image":"gallery/tess1367386538.jpg"}
]
4

1 回答 1

3

尝试

$jsonData = json_encode($response['posts']);
于 2013-05-02T05:26:53.043 回答