JSON decode php problems
Hello I am rewriting my problem in a more clear way. I have a javascript array just like this:
var values=new Array('this is my "name"',en开发者_运维百科codeURIComponent('me&you&there'),encodeURIComponent('"£$%&/'),'0');
var jsonval=JSON.stringify(values);
$.ajax({
type:'post',
url:'dosomething.php',
data:'action=getdata&myvalues='+jsonval
});
I have to use encodeURIComponent cause of posting with ajax. And at php side i have this:
$myvals=json_decode($_POST['myvalues'],true);
This fails from decoding the object. an echo of $_POST['myvalues'] something like give this:
{"1":"this is my "name"","2":"me&you&there","3":""£$%&/","4":"0"}
This seems not to be a valid json object beacause it has """, double quotes insides. Any one know how to avoid this problem? Thanks
Just a guess, but would escaping your double-quote beside all the special characters with a \
work?
var values=new Array('this is my "name"',encodeURIComponent('me&you&there'),encodeURIComponent('\"£$%&/'),'0');
var jsonval=JSON.stringify(values);
$.ajax({
type:'post',
url:'dosomething.php',
data:'action=getdata&myvalues='+jsonval
});
精彩评论