2017-05-26 53 views
-1

test.php的PHP,JSON語法錯誤:JSON.parse:在line在對象屬性值1

<?php 

    require_once __DIR__ . '/vendor/autoload.php'; 

    $urlPaczkomaty = "http://api.paczkomaty.pl/?do=listmachines_xml"; 
    $curl = new Curl\Curl(); 
    $curl->get( $urlPaczkomaty ); 

    $xml = simplexml_load_string($curl->rawResponse); 
    $json = utf8_encode ( json_encode($xml) ); 
    $arrList = json_decode($json, TRUE); 

    $fieldsToOut = array(
     'name', 
     'type', 
     'postcode', 
     'province', 
     'street', 
     'town', 
     'latitude', 
     'longitude', 
     'paymentavailable', 
     'status' 
); 

    $key = "machine"; 

    if(empty($arrList[ $key ])){ 
     throw new \Exception("no key"); 
    } 
    $out = array(); 
    $i = 0; 
    foreach($arrList[ $key ] as $item ){ 
     foreach( $fieldsToOut as $field){ 
      if(empty($field ) ){ 
       die('iii'); 
      } 
      if(empty($item[ $field ])){ 
       die(" no key: ". $field. " in = ".(empty($item[ 'name' ]) ? '' : $item[ 'name' ]) ); 
       $item[ $field ] = 'xxxxx'; 
      } 
      $out[ $i ][$field] = $item[ $field ]; 
     } 
     $i++; 
    } 

header('Content-Type: application/json'); 
echo json_encode($out); 

composer.json

{ 
    "require": { 
     "php-curl-class/php-curl-class": "^4.10" 
    } 
} 

在Firefox後預期 '' 或 '}' ,當我執行(Debian的,阿帕奇): http://test.loc/test.php 我收到folowwing錯誤(不一樣):

SyntaxError: JSON.parse: expected ',' or '}' after property value in object at line 1 column 129650 of the JSON data 

or 

SyntaxError: JSON.parse: expected ':' after property name in object at line 1 column 261200 of the JSON data 

在我的當地環境,即xamp,windows 10工作沒有錯誤。

有什麼建議嗎?

祝你好運 Robert。

+0

首先,我建議將'JSON_PRETTY_PRINT'傳遞給'json_encode'。這將爲您提供格式化的JSON,因此您可以獲得比「列261200」更有用的內容...之後,查看正在讀取的JSON,特別是(已更新)錯誤消息中指示的行。 –

回答

0

問題在Firefox中,解析JSON解決

我刪除的插件(插件)。

Robert

相關問題