-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

?>

2 番目の json データが機能していません。

2 つの 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 に答える