Я новичок в 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": ""}
]
}
Все работало хорошо.
Благодарю.