使用 php 从 mysql 检索 json

Retrieve json from mysql using php

我是 android 的新手,正在学习本教程

http://www.androidhive.info/2014/06/android-facebook-like-custom-listview-feed-using-volley/

我想以相同的格式生成我的 json。

我该怎么做?

这是我管理的

使用前置标签

<pre>
<?php print_r($data); ?>
</pre>

<?php

echo '<pre>';
print_r($data);
echo '</pre>';

?>

您应该将结果封装到一个密钥中。

例如:

$shops = [['name'=>'teo'],['name'=>'pio']];
$result = ['shops'=>$shops];
echo json_encode($result);

输出:

{"shops":[{"name":"teo"},{"name":"pio"}]}

我已经成功了

我在我的服务器中创建了一个文件并将其命名为 feed.json 然后放置了这段代码

{
"feed": [
    {
        "id": 1,
        "name": "National Geographic Channel",
        "image": "http://api.androidhive.info/feed/img/cosmos.jpg",
        "status": "\"Science is a beautiful and emotional human endeavor,\" says Brannon Braga, executive producer and director. \"And Cosmos is all about making science an experience.\"",
        "profilePic": "http://api.androidhive.info/feed/img/nat.jpg",
        "timeStamp": "1403375851930",
        "url": null
    },
    {
        "id": 2,
        "name": "TIME",
        "image": "http://api.androidhive.info/feed/img/time_best.jpg",
        "status": "30 years of Cirque du Soleil's best photos",
        "profilePic": "http://api.androidhive.info/feed/img/time.png",
        "timeStamp": "1403375851930",
        "url": "http://ti.me/1qW8MLB"
    },
    {
        "id": 5,
        "name": "Abraham Lincoln",
        "image": null,
        "status": "That some achieve great success, is proof to all that others can achieve it as well",
        "profilePic": "http://api.androidhive.info/feed/img/lincoln.jpg",
        "timeStamp": "1403375851930",
        "url": null
    },
    {
        "id": 3,
        "name": "Discovery",
        "image": "http://api.androidhive.info/feed/img/discovery_mos.jpg",
        "status": "A team of Austrian scientists has developed a laser system that causes fruit flies to dance.",
        "profilePic": "http://api.androidhive.info/feed/img/discovery.jpg",
        "timeStamp": "1403375851930",
        "url": "http://dsc.tv/xmMxD"
    },
    {
        "id": 4,
        "name": "Ravi Tamada",
        "image": "http://api.androidhive.info/feed/img/nav_drawer.jpg",
        "status": "Android Sliding Menu using Navigation Drawer",
        "profilePic": "http://api.androidhive.info/feed/img/ravi_tamada.jpg",
        "timeStamp": "1403375851930",
        "url": "http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/"
    },
    {
        "id": 6,
        "name": "KTM",
        "image": "http://api.androidhive.info/feed/img/ktm_1290.jpg",
        "status": "\"The Beast\" KTM 1290 Super Duke",
        "profilePic": "http://api.androidhive.info/feed/img/ktm.png",
        "timeStamp": "1403375851930",
        "url": ""
    },
    {
        "id": 7,
        "name": "Harley-Davidson",
        "image": "http://api.androidhive.info/feed/img/harley_bike.jpg",
        "status": "We’re assembling riders of every style, bike, and passion. If you ride with conviction, ride with us. You have 24 days to get ready for World Ride. Prepare by visiting:",
        "profilePic": "http://api.androidhive.info/feed/img/harley.jpg",
        "timeStamp": "1403375851930",
        "url": "http://bit.ly/1wmBWaN"
    },
    {
        "id": 8,
        "name": "Rock & Girl",
        "image": "http://api.androidhive.info/feed/img/rock.jpg",
        "status": "A long time back...",
        "profilePic": "http://api.androidhive.info/feed/img/rock_girl.jpg",
        "timeStamp": "1403375851930",
        "url": ""
    },
    {
        "id": 8,
        "name": "Gandhi",
        "image": null,
        "status": "An eye for an eye will make the whole world blind.",
        "profilePic": "http://api.androidhive.info/feed/img/gandhi.jpg",
        "timeStamp": "1403375851930",
        "url": ""
    },
    {
        "id": 9,
        "name": "LIFE",
        "image": "http://api.androidhive.info/feed/img/life_photo.jpg",
        "status": "In 1965, LIFE photographer Bill Ray spent weeks with the Hells Angels, but his amazing photos never ran in the magazine",
        "profilePic": "http://api.androidhive.info/feed/img/life.jpg",
        "timeStamp": "1403375851930",
        "url": "http://ti.me/1rfcQa4"
    },
    {
        "id": 10,
        "name": "Shakira",
        "image": "http://api.androidhive.info/feed/img/shakira_la_la.png",
        "status": "Download La La La (Brazil 2014) from iTunes:",
        "profilePic": "http://api.androidhive.info/feed/img/shakira.jpg",
        "timeStamp": "1403375851930",
        "url": "http://smarturl.it/FWCalbum?IQid=sh"
    },
    {
        "id": 11,
        "name": "A. R. rahman",
        "image": "http://api.androidhive.info/feed/img/ar_bw.jpg",
        "status": "",
        "profilePic": "http://api.androidhive.info/feed/img/ar.jpg",
        "timeStamp": "1403375851930",
        "url": ""
    }
]

}

一切正常。 谢谢