2017-05-26 77 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