JSONArray末尾的不需要的逗号

时间:2019-05-13 13:41:12

标签: php arrays json comma

由我的API生成的此页面的Json无效,因为它包含在JSONArray“ appelliLista”的末尾,它是一个逗号,因此它期望有更多元素,并且不可用。有办法删除它吗?尝试在没有逗号的情况下模拟通话,并且一切正常;

JSON

{  
   "service":"appelliLista2",
   "status-code":200,
   "status-description":"success",
   "time-spent":0.196921,
   "server-time":"13/05/2019-03:22:40pm",
   "result":{  
      "appelliLista":[  
         {  
            "Attivita didattica":"SISTEMI OPERATIVI",
            "Appello":"22/05/2019",
            "Iscrizione":"07/05/201920/05/2019",
            "Descrizione":"SISTEMI OPERATIVI",
            "Sessioni":"2018/2019",
            "link":"APP_ID=62&CDS_ESA_ID=10047&ATT_DID_ESA_ID=5868&ADSCE_ID=20148812&AA_OFF_ID=2014&CDS_ID=10047&PDS_ID=9999&AA_ORD_ID=2013&ISCR_APERTA=1&TIPO_ATTIVITA=1&TIPO_APP_COD=0"
         }
      ],

   }
}

函数生成JSON

public function appelliLista2($contentString, $service, $uni, $payload)
    {

        $parserCommons = new parserCommons();
        // TRASFORMA LA STRING IN UN ARRAY DI OGGETTI
        $DOMArray = $parserCommons->htmlToObj($contentString);

        //TROVA LA TABELLA
        $table = $parserCommons->findNodeById($DOMArray, 'table', 'app-tabella_appelli');

        // PARSA LA TABELLA
        $s = [1, 2, 3, 4, 5];
        $i = [0];
        $result = $parserCommons->parseTableNoHeader($table[0], $s, $i);

        $DTO['appelliLista'] = array();
        for($h = 1; $h <= sizeof($result); $h++){
            array_push($DTO['appelliLista'], $result[$h]);
        }



        return $DTO;

    }

0 个答案:

没有答案