抱歉.. 我英语很差
<?
//data_send.php ------------------
$json_data = '{"kim":{"age":"30","pay":"350"},"lee":{"age":"50","pay":"120"},"park":{"age":"40","pay":"180"}}'; // this json_data is working well
$json_data = json_encode($json_data);
?>
<form action="json_parse.php" method="post">
<input type=hidden name=json_data value=<?=$json_data?> >
<input type="submit">
</form>
<?
//json_parse.php ------------------
$json_data = $_REQUEST[json_data];
$json_data = str_replace('\\', '', $json_data);
$output = json_decode($json_data);
echo $output->{'park'}->{'pay'};
//180 is printed
?>
<?
//data_send2.php ------------------
$json = '{"mem_nm":{"disp":"Name","type":"field","param":"0"},"mem_id":{"disp":"Id","type":"field","param":"1"},"mem_email":{"disp":"E-mail","type":"field","param":"2"},"mem_mobile":{"disp":"Phone","type":"bind","param","1-3|-"},"mem_out_yn":{"disp":"Retire","type":"conv","param":"aaa"},"reg_dt":{"disp":"JoinDate","type":"func","param":"convertDateTime"}}'; //this json_data not work
$json_data = json_encode($json_data);
?>
<form action="json_parse2.php" method="post">
<input type=hidden name=json_data value=<?=$json_data?> >
<input type="submit">
</form>
<?
//json_parse2.php ------------------
$json_data = $_REQUEST[json_data];
$json_data = str_replace('\\', '', $json_data);
$output = json_decode($json_data);
echo $output->{'mem_nm'}->{'type'};
//期望'字段'被打印,但是打印不到
?>
第二个json数据不起作用。
我不知道两个json数据的区别。
请帮助..
答案 0 :(得分:1)
JSONLint说:
Parse error on line 20:
...nd", "param", "1-3|-"
----------------------^
Expecting ':'
这看起来很糟糕:
"mem_mobile": {
"disp": "Phone",
"type": "bind",
"param", // <-- right there should be a `:`
"1-3|-"
},
答案 1 :(得分:1)
如果我遇到这样的问题,我会使用json validator。
答案 2 :(得分:0)
检查你的“mem_mobile”,param之后的拼写错误