I have an multidimensional array
$array = array(
"Level1"=>array(
"Level11"=>array(
"level111"=>'value1',
"level112"=>'value2',
),
"Level12"=>array(
"level121"=>'value1',
"level122"=>'value2',
),
),
"Level2"=>array(
"Level21"=>array(
"level211"=>'value1',
"level212"=>'value2',
),
"Level22"=>array(
"level221"=>'value1',
"level222"=>'value2',
),
)
);
echo json_encode($array);
This encoded JSON is sent after receiving AJAX POST request using jQuery.
$.post(
'mypage.php',
{
param1: value1,
param2: value2
},
function(data) {
//Now I can access the 1st level JSON value easily like
alert(data.Level1);
// But
// I am trying to access the values like
alert(data.Level1.Level11.level112); //which is not possible
},
"json"
);
If you have understood my question, do you know how I could tackle this problem.
data.level1.level11.level112not possible?json_encode()? Btw evendata.level1should not work, because the key is namedLevel1(capital L).dt = data.level1; i = dt['level11'][level112]and I just created a sample of my code, I will correct it right away, I have 3 more levels in my actual code.