相同的数据不同的函数给出JSON错误

时间:2017-08-29 23:20:19

标签: php json

我已经在这个问题上工作了两个星期,我找不到错误背后的逻辑。工作的PHP是:

<?php
include('functions.php');

if (strpos(filter_input(INPUT_GET, 'PageName'),$Basic_Commands[0])!==FALSE){

$PageName= str_replace($Basic_Commands[0]."|","",filter_input(INPUT_GET, 'PageName'));
$ClearElements=ClearArray(CallData($Basic_Commands[0],'',"SELECT * FROM mytool WHERE page='".$PageName."'",'',''),'clearable','','==');
$SeedElements=ClearArray(ClearArray(CallData($Basic_Commands[0],'',"SELECT * FROM mytool WHERE page='".$PageName."'",'',''),'clearable','','=='),'category','seed','!==');

$SeedElements=OrganizeData($SeedElements,$Basic_Commands[0]);

file_put_contents('Log.txt', var_export($SeedElements, true), FILE_APPEND);

foreach ($SeedElements as $key => $value){    

    $SqlQuery=PrepareSql($SeedElements,$key,$Variable_holder,$Query_Variable_holder,$Basic_Status,"","");                    
    $SqlArray[]=array(
      'id' => $SeedElements[$key]['element_id'],
      'element'=> $SeedElements[$key]['element'], 
      'sql'=>  $SqlQuery[$key]
    );   
    //file_put_contents('Log.txt', var_export($SqlArray, true), FILE_APPEND);
    $ClearStr='';
    $test=CallData($Basic_Commands[0],$SqlArray[$key]['id'],$SqlArray[$key]['sql'],$ClearStr,$SqlArray[$key]['element']);    
    foreach ($ClearElements as $lock => $value){
    $ClearStr=$ClearElements[$lock]['element_id'].'|'.$ClearStr;}
    $test[0]['clear']=$ClearStr;    
    $data[$key]=$test[0];
 }//file_put_contents('Log.txt', var_export($data, true), FILE_APPEND);
   echo json_encode($data);        
}

如果我删除

  

功能 OrganizeData()

或者我保留, $ SeedElements 将具有相同的确切值。 然而,当我保持该功能时,我收到JSON错误。

  

SyntaxError:JSON.parse:第1行第1列的意外字符   JSON数据

功能 OrganizeData()如下:

function OrganizeData($ElementArray,$Command){
foreach($ElementArray as $key=>$value){
    //file_put_contents('Log.txt', var_export($ElementArray[$key]['e_action'], true), FILE_APPEND);
    $Action=Organizer($ElementArray[$key]['e_action']);
    $Table=Organizer($ElementArray[$key]['e_table']);
    $Record= Organizer($ElementArray[$key]['e_record']);
    $Descendant=Organizer($ElementArray[$key]['descendant']);

    $tester=Comparator($Action, $Table, $Record, $Descendant,$Command);

    $ElementArray[$key]['e_action']=$tester[0]['action'];
    $ElementArray[$key]['e_record']=$tester[0]['record'];
    $ElementArray[$key]['e_table']=$tester[0]['table'];
    $ElementArray[$key]['descendant']=$tester[0]['descendant'];

}

return $ElementArray;
}

function Organizer($stringtoorganize){

    $OrganArray=array();    
    if (strpos($stringtoorganize, '&&') !== false) {
    $OrganizerArr= explode("&&", $stringtoorganize);
    }else{
        $OrganizerArr[0]=$stringtoorganize;}
        //file_put_contents('Log.txt', var_export($OrganizerArr, true), FILE_APPEND);
    foreach($OrganizerArr as $key=>$value){
        if(strpos($OrganizerArr[$key], '<<>>') !== false){
           array_push($OrganArray,explode("<<>>", $OrganizerArr[$key]));
        }else{
       $OrganArray[$key]=$OrganizerArr[$key];}
    }
      //  foreach($OrganArray as $counter=>$value){
       // array_push($FinalArray, $OrganArray[$counter]);
   // }    

    return $OrganArray;    
}

function Comparator($Action,$Table,$Record,$Descendant,$Command){

    if($Command=="Loading" || $Command=="Changing"){
        $Command="select";
    }

    $testing[]=array(
       'action'=>"",
       'table'=>"",
       'record'=>"",
       'descendant'=>""
    );
    $comm=array("action","table","record","descendant");

    $CalculateLength=array();

    $Indicator=array();
    $Compare= array($Action,$Table,$Record,$Descendant);
   // $Comparator= array('action'=>$Action,'table'=>$Table,'record'=>$Record,'descendant'=>$Descendant);

    foreach($Compare as $key=>$value){
        array_push($CalculateLength, count($Compare[$key]));
    }
    for($i=1;$i<=max($CalculateLength);$i++){
        array_push($Indicator, $i*100);
    }       
    foreach($Indicator as $loop=>$value){
    foreach($Compare as $key=>$value){
    foreach($Indicator as $j=>$value){        
        if($Compare[$key][$j][0]==$Indicator[$loop]){
          $testing[$loop][$comm[$key]]=$Compare[$key][$j][1];
          //file_put_contents('Log.txt', var_export($Comparator[$key][$j][1], true), FILE_APPEND);
        } } } }

    if($testing[0]['action']==''){
        foreach($comm as $key=>$value){
            $testing[0][$comm[$key]]=$Compare[$key][0];
        }
    }else{
        foreach($testing as $key=>$value){
            if($testing[$key][$comm[0]]!==$Command){
                unset($testing[$key]);
            }            
        }}    
        return $testing;     
}

问题是,如果使用函数错误,我怎么得到相同的值,如果不是它工作正常?我错过了什么?

0 个答案:

没有答案