【问题标题】:How to get a Particular field from an object array in a text file如何从文本文件中的对象数组中获取特定字段
【发布时间】:2015-07-13 13:18:29
【问题描述】:

我正在尝试使用 file_get _contents 从文本文件中仅获取 refresh_token 字段。请任何人解决这个问题。

{"access_token":"XXXX","token_type":"bearer","expires_in":3600,"refresh_token":"XXXX"}

【问题讨论】:

  • echo $object->refresh_token
  • 试过不行 :(

标签: php arrays api file-get-contents


【解决方案1】:

对于 json 操作,您应该使用 json_decode

$str= file_get_contents(some.txt);
$array = json_decode($content);
echo $array->access_token;

【讨论】:

    【解决方案2】:

    这是一个json字符串

    $content = file_get_contents([...]);
    $arr = json_decode($content);
    
    echo $arr->access_token;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-31
      • 2016-04-16
      相关资源
      最近更新 更多