我搜索了很多,但发现很少有方法可以找到我的 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"}]';
如何找到我的 JSON 数组中的对象数量?
最佳答案
您需要decode the json对象,然后计算其中的元素..
$json_array = json_decode($json_string, true);
$elementCount = count($json_array);
关于php - 查找 json 数组中的对象数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15872554/