2012-04-01 114 views

回答

2

我不想给你解决方案,所以下面的内容应该足以让你开始。

  1. 阅读使用file_get_contents
  2. 使用json_decode

你的代码应该是这个样子解析JSON字符串转换成一个PHP对象的JSON数据:

$url = "http://www.instamapper.com/api?action=getPositions&key=584014439054448247&num=10&format=json"; 
$contents = file_get_contents($url); 
$jsonObj = json_decode($contents); 
1

你的意思是喜欢这个?

<?php 

$jsonurl = "http://search.twitter.com/trends.json"; 
$json = file_get_contents($jsonurl,0,null,null); 
$json_output = json_decode($json); 

foreach ($json_output->trends as $trend) 
{ 
    echo "{$trend->name}\n"; 
}