JSON解析-输出NULL-PHP [英] JSON parsing - outputs NULL - PHP

查看:142
本文介绍了JSON解析-输出NULL-PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查询一个输出json的第三方服务.

I am querying a 3rd party service which outputs json.

$data = json_decode($result,true);
var_dump ($data);

$ data持有:

{"response":{"status":"OK","token":"hbapi:187089:586e655ed1f9c:nym2","dbg_info":{"instance":"53.bm-hbapi.prod.ams1","slave_hit":false,"db":"master","parent_dbg_info":{"instance":"64.bm-hbapi.prod.nym2","slave_hit":false,"db":"master","parent_dbg_info":{"instance":"45.bm-api.prod.nym2","slave_hit":false,"db":"master","time":664.07299041748,"version":"1.17","warnings":[],"slave_lag":0,"start_microtime":1483629917.8571},"awesomesauce_cache_used":false,"count_cache_used":false,"uuid":"39e1c17a-7fe4-58ac-9486-c4dd5bbf96a3","warnings":[],"time":1159.7349643707,"start_microtime":1483629917.7835,"version":"1.17.150","slave_lag":0,"output_term":"not_found"},"awesomesauce_cache_used":false,"count_cache_used":false,"uuid":"286ca4bc-6964-50ad-b241-ff9df1304278","warnings":[],"time":1347.2578525543,"start_microtime":1483629917.6534,"version":"1.17.150","slave_lag":0,"output_term":"not_found","master_instance":"64.bm-hbapi.prod.nym2","proxy":true,"master_time":1159.7349643707}}}

我正在尝试获取令牌值.

I am trying to get the token value.

我尝试了

$token = $data["response"][0]["token"];

我得到NULL

我也尝试过

$token = $data['response'][0]['token'];

我仍然得到NULL.

我查看了如何访问数组/对象?和其他线程-找不到问题.

I have looked at How can I access an array/object? and other threads - can't find the issue.

推荐答案

如果不是数组,为什么要访问pos [0]?

Why are you accessing the pos [0] if isn't an array?

相反,尝试像这样访问所需的参数:

Instead of that try to access to the desired parameter like this:

$token = $data["response"]["token"];

这篇关于JSON解析-输出NULL-PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆