Reputation: 53
I have retrieved a PHP variable session that contains a JSON object. The JSON object is the following:
var jsonObject = {
"menu":{
"intro":{
"intosub":"sub_1"
},
"vis":{
"visub":"sub_2"
}
}
};
How can I know the length of a part of this JSON object? That is, I want to know how much elements that contain the key Intro
and the same with key vis
.
I have reviewed some post about this issue, and I found that I have to change the structure of JSON object, but this is not possible. Is there any other way in order to do this?
Upvotes: 2
Views: 82
Reputation: 1062
First, parse json to php associative array, use json_decode(your_var, true) . You will get a multidimensional array. Then use php count function on desired subarray
Upvotes: 1