Php 如何从文本文件中的对象数组中获取特定字段

Php 如何从文本文件中的对象数组中获取特定字段,php,arrays,api,file-get-contents,Php,Arrays,Api,File Get Contents,我试图使用file\u get\u内容从文本文件中仅获取refresh\u令牌字段。请任何人解决这个问题 {"access_token":"XXXX","token_type":"bearer","expires_in":3600,"refresh_token":"XXXX"} 这是一个json字符串 $content = file_get_contents([...]); $arr = json_decode($content); echo $arr->access_token;

我试图使用file\u get\u内容从文本文件中仅获取refresh\u令牌字段。请任何人解决这个问题

{"access_token":"XXXX","token_type":"bearer","expires_in":3600,"refresh_token":"XXXX"}
这是一个json字符串

$content = file_get_contents([...]);
$arr = json_decode($content);

echo $arr->access_token;

对于json操作,您应该使用
json\u decode

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

echo$object->refresh\u token
尝试了不工作的情况:(