访问特定的JSON值

编程入门 行业动态 更新时间:2024-10-07 14:21:59
本文介绍了访问特定的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值

本文发布于:2023-11-26 21:41:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635298.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!