【发布时间】:2015-09-08 15:39:17
【问题描述】:
我有一个带有 Yahoo Weather API 数据的 JSON 数组:
"query":{
"count":1,
"created":"2015-09-08T15:33:25Z",
"lang":"en-US",
"results":{
"channel":{
"item":{
"condition":{
"code":"30",
"date":"Tue, 08 Sep 2015 11:13 am EDT",
"temp":"81",
"text":"Partly Cloudy"
}
}
}
}
}
我只需要获取temp 和text 并将它们保存为变量...我该怎么做?
我尝试了编码、解码、subtr 和其他一些方法,但似乎无法正确使用语法。 我已经尝试过来自Convert JSON string to PHP Array的说明
这是我网站上的代码:
$BASE_URL = "http://query.yahooapis.com/v1/public/yql";
$yql_query = 'select item.condition from weather.forecast where woeid in (select woeid from geo.places(1) where text="'.$city.', '.$state.'")';
$yql_query_url = $BASE_URL . "?q=" . urlencode($yql_query) . "&format=json";
// Make call with cURL
$session = curl_init($yql_query_url);
curl_setopt($session, CURLOPT_RETURNTRANSFER,true);
$json = curl_exec($session);
// Convert JSON to PHP object
$phpObj = json_decode($json);
echo '<br><br><br><br>';
echo $json;
【问题讨论】:
-
我尝试了该链接中的建议 (echo $json->temp;) 但它没有回显任何内容
-
console.log($json) 得到什么?
-
Uncaught ReferenceError: $json is not defined(...) 我根本没有使用 javascript,只有 php