php – 查找json数组中的对象数
发布时间:2020-12-13 13:17:03 所属栏目:PHP教程 来源:网络整理
导读:我搜索了很多,我找到了一些方法来查找我的 JSON数组的长度.我试过了: 数 json.length 但这些返回1,而不是实际长度.我想用PHP来展示它. 我的json是: $huge = '[{"location":[{"building":["Default Building"],"name":"Default Location"}],"name":"Default
我搜索了很多,我找到了一些方法来查找我的
JSON数组的长度.我试过了:
>数 但这些返回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"}]'; 如何在JSON数组中找到对象的数量?
你需要
decode the json对象,然后计算其中的元素..
$json_array = json_decode($json_string,true); $elementCount = count($json_array); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |