-1
<?
//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'};  
//expect 'field' is printed, but nothig is printed

?>

第二个 json 数据不起作用。

我不知道两个json数据的区别。

4

3 回答 3

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|-"
},
于 2013-05-23T01:42:54.397 回答
1

如果我遇到这样的问题,我会使用json 验证器。

于 2013-05-23T01:43:21.977 回答
0

检查您的“mem_mobile”,参数后的错字

于 2013-05-23T01:44:28.793 回答