访问特定的JSON值 [英] Accessing specific JSON value

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

问题描述

我目前有一个变量$ return,其中包含JSON编码的数据,其输出为:

I currently have a variable $return which contains JSON-encoded data, which prints out as:

({0:{data:[[0, null], [1, null], [2, null], [3, null], [4, null], [5, null], [6, null], [7, null], [8, null], [9, null], [10, null], [11, null], [12, null], [13, null], [14, null], [15, null], [16, null], [17, null], [18, null], [19, null], [20, null], [21, null], [22, null], [23, null]], label:null, count:null}, 

等(太多,无法复制和粘贴).基本上,我想做的是找出data:[0,null]的值是否为null,然后根据结果创建一个if else语句.如果为空,则需要显示一条消息无可用数据",但是如果它包含一个值,则需要显示该值.

and so on (too much to copy and paste). Basically what I want to do is find out whether the value of data:[0,null] is null, and then create an if else statement dependant on the result. If it is null, I need to show a message saying "No data available", but if it contains a value I need the value to be displayed.

有人可以解释一下我如何访问该特定值吗?

Could someone explain how I'd access that specific value please?

感谢您的帮助

推荐答案

$return=json_decode($return);
if($return['data'][0]){
// what to do if null
}else{
// what to do if not (alternatively use elseif())
}

这篇关于访问特定的JSON值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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