开发者

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
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜