【问题标题】:Retrieve json from mysql using php使用php从mysql中检索json
【发布时间】:2015-10-13 09:09:51
【问题描述】:

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

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

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

我该怎么做?

这就是我所管理的

【问题讨论】:

  • 请贴出生成 JSON 的代码,说明您的期望(“以相同格式”太含糊了)。谢谢!

标签: php mysql json mysqli android-volley


【解决方案1】:

您应该将结果包含在一个键中。

举例:

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

输出:

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

【讨论】:

    【解决方案2】:

    使用前置标签

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

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

    【讨论】:

    • 我想要一个可检索此类数据的示例 php 文件。
    【解决方案3】:

    我已经成功了

    我在我的服务器中创建了一个文件并将其命名为 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": ""
        }
    ]
    

    }

    一切运行良好。 谢谢。

    【讨论】:

      猜你喜欢
      • 2012-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-25
      • 1970-01-01
      • 2015-05-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多