小编Tim*_*ott的帖子

将 JSON 字符串转换为 PHP 变量

我有一个带有 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"
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我只需要得到temptext,并将其保存为变量......我该怎么办呢?

我尝试过编码、解码、subtr 和其他一些方法,但似乎无法获得正确的语法。我已经尝试过将 JSON 字符串转换为 PHP 数组的说明

这是我网站上的代码:

  $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); …
Run Code Online (Sandbox Code Playgroud)

php json encode decode

2
推荐指数
1
解决办法
9312
查看次数

标签 统计

decode ×1

encode ×1

json ×1

php ×1