2012-04-01 112 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"; 
}