我目前正在尝试使用http://getpocket.com/developer/docs/v3/retrieve路由将我的php应用程序绑定到Pocket app api。连接本身很好,我可以得到返回的json。返回的json如下:
{
"status": 1,
"complete": 1,
"list": {
"446599840": {
"item_id": "446599840",
"resolved_id": "446599840",
"given_url": "http://www.theguardian.com/media-network/media-network-blog/2013/jan/07/panasonic-changing-consumer-retail-technology",
"given_title": "The changing consumer-retailer relationship: interview with Panasonic | Med",
"favorite": "0",
"status": "0",
"time_added": "1395140204",
"time_updated": "1395140204",
"time_read": "0",
"time_favorited": "0",
"sort_id": 6,
"resolved_title": "Guardian Professional",
"resolved_url": "http://www.theguardian.com/media-network/media-network-blog/2013/jan/07/panasonic-changing-consumer-retail-technology",
"excerpt": "Time to give call centres a facelift? Businesses have an opportunity to reinvent their customer-service by applying new technologies in the right areas, says Simon Parkinson. Photograph: 13/Ocean/Corbis",
"is_article": "0",
"is_index": "0",
"has_video": "0",
"has_image": "1",
"word_count": "0"
},
"482104798": {
"item_id": "482104798",
"resolved_id": "482104798",
"given_url": "http://www.theintegratedretailer.com/news/795/retailers-urged-to-embrace-techno…o-create-knowledge-sharing-high-performing-and-highly-engaged-workforces/",
"given_title": "Retailers urged to embrace technology to create knowledge sharing, high per",
"favorite": "0",
"status": "0",
"time_added": "1395144267",
"time_updated": "1395146556",
"time_read": "0",
"time_favorited": "0",
"sort_id": 3,
"resolved_title": "Retailers urged to embrace technology to create knowledge sharing, high performing and highly engaged workforces",
"resolved_url": "http://www.theintegratedretailer.com/news/795/retailers-urged-to-embrace-techno…o-create-knowledge-sharing-high-performing-and-highly-engaged-workforces/",
"excerpt": "With evidence suggesting that businesses that achieve high levels of sustainable employee engagement average an operating margin close to three times higher than those with high traditional engagement, large retailers are being urged to explore the potential that new technology can play in improv",
"is_article": "1",
"is_index": "0",
"has_video": "0",
"has_image": "1",
"word_count": "502"
},
"571816084": {
"item_id": "571816084",
"resolved_id": "571816084",
"given_url": "http://www.hrreview.co.uk/supplier-news/supplier-training-development/british-sme-lights-the-fuse-for-free-online-education-anywhere-in-the-world/50353",
"given_title": "British SME lights the Fuse for free online education anywhere in the world",
"favorite": "0",
"status": "0",
"time_added": "1395144314",
"time_updated": "1395144314",
"time_read": "0",
"time_favorited": "0",
"sort_id": 0,
"resolved_title": "British SME lights the Fuse for free online education anywhere in the world",
"resolved_url": "http://www.hrreview.co.uk/supplier-news/supplier-training-development/british-sme-lights-the-fuse-for-free-online-education-anywhere-in-the-world/50353",
"excerpt": "A British SME, which has developed an online learning platform for some of the UK’s leading retailers, will demonstrate how commercial organisations implementing its technology are simultaneously supporting the social goal of delivering free secondary education content to any student anywhere in",
"is_article": "1",
"is_index": "0",
"has_video": "0",
"has_image": "1",
"word_count": "429"
},
"571816595": {
"item_id": "571816595",
"resolved_id": "0",
"given_url": "http://www.hrreview.co.uk/supplier-news/supplier-hr-strategy-practice/organisations-can-now-create-their-own-online-central-knowledge-bank/50085",
"given_title": "Organisations can now create their own online central knowledge bank",
"favorite": "0",
"status": "0",
"time_added": "1395144298",
"time_updated": "1395144298",
"time_read": "0",
"time_favorited": "0",
"sort_id": 1
},
"571820367": {
"item_id": "571820367",
"resolved_id": "571820367",
"given_url": "http://www.palife.co.uk/surveys-current-affairs/item/489-and-finally-something-for-the-boss",
"given_title": "And finally... something for the boss",
"favorite": "0",
"status": "0",
"time_added": "1395144281",
"time_updated": "1395144281",
"time_read": "0",
"time_favorited": "0",
"sort_id": 2,
"resolved_title": "And finally... something for the boss",
"resolved_url": "http://www.palife.co.uk/surveys-current-affairs/item/489-and-finally-something-for-the-boss",
"excerpt": "At PA Life we're devoted to bringing you the very latest news, tips, advice and recommendations on a whole smorgasbord of topics that we hope are of interest to you in your professional lives.",
"is_article": "1",
"is_index": "0",
"has_video": "0",
"has_image": "1",
"word_count": "310"
},
"571822317": {
"item_id": "571822317",
"resolved_id": "299897045",
"given_url": "http://www.learningsolutionsmag.com/articles/1004/?utm_campaign=lsmag&utm_medium=some&utm_source=linkedin&goback=.gde_1821266_member_160113156",
"given_title": "EMEA Reporter: African Virtual School is Model for World by Nic Laycock : L",
"favorite": "0",
"status": "0",
"time_added": "1395140611",
"time_updated": "1395140611",
"time_read": "0",
"time_favorited": "0",
"sort_id": 4,
"resolved_title": "EMEA Reporter: African Virtual School is Model for World",
"resolved_url": "http://www.learningsolutionsmag.com/articles/1004/",
"excerpt": "What do you do when you have to serve out an employment restraint (a non-compete clause)? Go and found a social impact company, of course, using your income from your previous employment!",
"is_article": "1",
"is_index": "0",
"has_video": "0",
"has_image": "0",
"word_count": "774"
},
"571823356": {
"item_id": "571823356",
"resolved_id": "0",
"given_url": "http://uk.prweb.com/releases/2010/12/prweb4870124.htm",
"given_title": "Fusion Universal Wins Coveted E-Learning Award Using Panviva's SupportPoint",
"favorite": "0",
"status": "0",
"time_added": "1395140303",
"time_updated": "1395140304",
"time_read": "0",
"time_favorited": "0",
"sort_id": 5
}
},
"since": 1396516912
}
然而,问题是我似乎无法有效地解析这个问题。似乎并不是整个阵列的入口点('列表'失败)。我认为每个的数字条目也给我带来了问题。基本上我试图遍历那些项目来拉取相关数据,即“给定标题”。对于每个条目,但无论哪种解析方法,我都无法得到结果。
我目前在php中使用这种格式(显然是错误的):
<?php
foreach ($result['list'] as $item){
echo "Item: ", $item['item_id'];
}
var_dump(json_decode($result,true));
?>
非常感谢任何帮助。
非常感谢提前。
答案 0 :(得分:0)
拳头,您需要将json数据转换为数组:
$result=json_decode($result);
foreach ($result['list'] as $item){
echo "Item: ", $item['item_id'];
}
答案 1 :(得分:0)
首先需要将json数据转换为数组。
&#34; true&#34;参数确保它返回一个关联数组而不是一个对象。 预标签用于格式化。
$result = json_decode($json, true);
echo "<pre>";
foreach ($result["list"] as $value) {
print_r($value);
}
echo "</pre>";