使用json_decode解析后,返回 对象
<?php
require('json.php');
//$str = '[{"F_ID":"1311","F_TYPE":"5","F_VALUE":"211"},{"F_ID":"3112","F_TYPE":"2","F_VALUE":"大"},{"F_ID":"1233","F_TYPE":"7","F_VALUE":""}]';
//$arr = array("s"=>"sss");
//$json = json_encode($str);
// $jsonObj=json_decode($str);
//echo json_encode($jsonObj);
//echo JSON($arr);
//$json = array();
//$json[] = array("s"=>array("ss"=>"OK","t"=>'111'));
//echo json_encode($json);
$getListRs = array(
'taskstruct' => '[{"F_ID":"1311","F_LABEL":"%E6%98%AF%E5%90%A6%E5%8F%AF%E6%9C%8D%E5%8A%A1","F_TYPE":"5","F_OPTIONAL":"0","F_CONTENT":[{"VALUE":"211","LABEL":"%E6%98%AF"},{"VALUE":"212","LABEL":"%E5%90%A6"}],"F_DEFAULT":"211"},{"F_ID":"3112","F_LABEL":"%E5%8E%9F%E5%9B%A0","F_TYPE":"2","F_OPTIONAL":"0"},{"F_ID":"1233","F_LABEL":"%E6%8B%8D%E5%B0%8F%E5%9B%BE","F_TYPE":"7","F_OPTIONAL":"1"}]',
'valjson' => '[{"F_ID":"1311","F_TYPE":"5","F_VALUE":"211"},{"F_ID":"3112","F_TYPE":"2","F_VALUE":"B%E9%82%A3%E4%B8%AA"},{"F_ID":"1233","F_TYPE":"7","F_VALUE":""}]'
);
//print_r( json_decode($getListRs['taskstruct']) );
$decode_taskstruct = json_decode($getListRs['taskstruct']);
$decode_valjson = json_decode($getListRs['valjson']);
$jsonArr = array();
for($i=0;$i<count($decode_taskstruct);++$i){
if($decode_taskstruct[$i]->F_ID==$decode_valjson[$i]->F_ID){
$push = array();
$push['F_LABEL'] = $decode_taskstruct[$i]->F_LABEL;
$push['F_TYPE'] = $decode_taskstruct[$i]->F_TYPE;
if($decode_taskstruct[$i]->F_TYPE==5 || $decode_taskstruct[$i]->F_TYPE==6 || $decode_taskstruct[$i]->F_TYPE==9){
for($ii=0;$ii<count($decode_taskstruct[$i]->F_CONTENT);++$ii){
if($decode_valjson[$i]->F_VALUE==$decode_taskstruct[$i]->F_CONTENT[$ii]->VALUE){
$push['F_VALUE'] = $decode_taskstruct[$i]->F_CONTENT[$ii]->LABEL;
}
}
}
else{
$push['F_VALUE'] = $decode_valjson[$i]->F_VALUE;
}
$jsonArr[] = $push;
}
}
echo json_encode($jsonArr);
?>