dqqyp90576 2015-09-01 11:21
浏览 53

Php中的JSON无法正常工作

I have a problem and do not know what the problem is. I have a javascript variable in my html. which is:

  var people = '{"names": ["Matthew", "Lucas", "Todd", "Roxie", "Kyle", "Ken", "Gideon"], "surnames": ["Patel", "Lee", "Ingram", "Richter", "Katayanagi", "Katayanagi", "Graves"]}';

I parse the variable on one function in my script and use it. Everything works fine.

var mydata = JSON.parse(people);

But then I need to send the data to a php file, I send it by wrtting the data to a hidden input.

 var strObject = JSON.stringify(mydata);


var replaced = strObject.replace(/\//g, '');


oFormObject = document.forms['theForm'];
oFormObject.elements["jsonData"].value = replaced;

After which I try to encode it in my decode.php using:

$obj = $_POST['jsonData'];



json_decode($obj);
$s = stripslashes($obj);


var_dump($s); 

But when I do a var_dump($s) I get this output:

string(147) "{"names":["Matthew","Lucas","Todd","Roxie","Kyle","Ken","Gideon"],"surnames":["Patel","Lee","Ingram","Richter","Katayanagi","Katayanagi","Graves"]}"

Thus, I cannot output the contents in $s.Any suggestions.Please let me know if you need more information. BTW, its a homework assignment and I am stuck with the last section.

  • 写回答

3条回答 默认 最新

  • doudeng5218 2015-09-01 11:33
    关注

    try saving json_decode($obj) to a variable and var_dump that something like

    var $temp = json_decode($obj);
    var_dump($temp);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题