dongqiongzheng0615 2016-09-13 12:44
浏览 124
已采纳

如何将字符串转换为数组

So I have obtained a string that looks like this:

string(138) "{"access_token":"#############","token_type":"Bearer","expires_in":3600}"

But I need to access only the "#############" (which is the access token) but in order to do that I need to convert this string to an array. I have tried like this:

//this is the string
$access = $tokenNew["extra_details"];
//here I convert it to an array
$access_token = explode(' ', $access);

But by doing that I get something like this:

array(1) {
   [0] => string(138) "{"access_token ":"##########","token_type ":"Bearer ","expires_in ":3600}"
}

Any ideas why? Any help is welcomed! Thank you for your time!

  • 写回答

2条回答 默认 最新

  • dongyi5070 2016-09-13 12:47
    关注

    Your string looks like a JSON. You could try the json_decode function on your string.

    $array = json_decode($your_string, true);
    echo $array['access_token'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器