I have the following array:
Array
(
[0] => Array
(
[id] => 179
[user_id] => 191
[behandeling] => msg
)
)
For some reason i can’t get the value of ‘behandeling’ .. i have tried several ways, like:
console.debug(msg[0].behandeling);
Some more info about building the array:
$d[] = array('id' => $row['id'],
'user_id' => $row['user_id'],
'behandeling' => $row['behandeling']);
//print_r($d);
//echo json_encode($d);
If i use print_r($d), the value of behandeling = CORRECT.
If i use json_encode($d), the value of behandeling will be null..
EDIT:
I think i found the problem.. When submitting the data, the data is being send unescaped in this way:
var data = 'actie=Wijzig&module=treatment&treatments=' + treatment.val();
This means if there are certains characters which need to be escaped, & etc.. the data string gets broken… which results in null and/or half msgs…
EDIT2:
The finding described above is very important, but describes a different section of the site. Saving the data is going fine now, but still having difficulties returning the value of the data of SOME messages..
As stated in the comments that’s a PHP array, you could try the following:
Update:
I believe Javascript is interpreting the JSON as a regular string due to your
content-typeheader.You should try adding
when outputting your JSON.
Alternatively, if for whatever reason you can’t change the headers and you’re using jQuery you can try:
Without jQuery you can use
evalhowever there are security implications involved.