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

({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语句。如果为空,则需要显示一条消息“无可用数据”,但是如果它包含一个值,则需要显示该值。

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

谢谢你的帮助

最佳答案

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

关于php - 访问特定的JSON值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7659968/

10-10 01:23
查看更多