php – 查找json数组中的对象数

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 查找json数组中的对象数脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
搜索了很多,我找到了一些方法来查找我的 JSON数组的长度.我试过了:

>数
> json.length

但这些返回1,而不是实际长度.我想用PHP来展示它.

我的json是:

$huge = '[{"location":[{"building":["Default Building"],"name":"Default Location"}],"name":"Default organization"},{"location":[{"building":["test_loc1_building1","test_loc1_building2"],"name":"test location1"},{"building":["test_loc2_building2"],"name":"test location2"}],"name":"test Organization"}]';@H_304_9@ 
 

何在JSON数组中找到对象的数量

你需要 decode the json对象,然后计算其中的元素..
$json_array  = json_decode($json_string,true);
 $elementCount  = count($json_array);

脚本宝典总结

以上是脚本宝典为你收集整理的php – 查找json数组中的对象数全部内容,希望文章能够帮你解决php – 查找json数组中的对象数所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。