dongqiulei6805 2011-07-03 03:52
浏览 144

如何处理JSON对象响应?

I was working with Google Oauth 2 and finally was able to get the access token. Google simply returned the access token in a JSON object. The output was printed out on my browser. Since I've never touched JSON or any other API before, I have no idea how to capture that JSON object so I can store the access token.

Example Output(obscured the actual data)

{
"access_token":"1/6GKFqrOr6000000004k10qgr000000GiUiRNbLnc",
"token_type":"Bearer",
"expires_in":3600,
"refresh_token": "1/Vx34LfPISDuX000000Kq_SJWIgf42FVs"
}

I tried the simple $token = $_POST['access_token']; which didn't work. json_decode also didn't work. I'm pretty sure I'm not doing it right here. Can someone tell me how you can interact with JSON object?

EDIT:

I guess my initial question is more rudimentary because I'm really new at API programming. What I want to know is how to encapsulate the browser response of a JSON object into a variable so my PHP script can dynamically decode the response. Currently, the browser just replied the content of the JSON object like I posted above but I don't know the object name or variable name like $object = {}. Is there any way to find out the object name or a way to put the response into an object or array dynamically?

  • 写回答

3条回答 默认 最新

  • doujianwei8217 2011-07-03 04:02
    关注

    Did you try with json_decode($output,true). If you give the second parameter it will return an associative array.

    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序