Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php jsonlint中的json无效_Php_Json - Fatal编程技术网

php jsonlint中的json无效

php jsonlint中的json无效,php,json,Php,Json,我有这样的脚本: <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"http://example.com/?weather=USA"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec ($ch); $row = json_decode($result, TRUE); echo $row['teston']; ?> { "

我有这样的脚本:

<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://example.com/?weather=USA");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec ($ch);
$row = json_decode($result, TRUE);
echo $row['teston'];
?>
{
    "test": ["test1", "test2", "test3"],
    "teston": "teston2",
    "debug": {}
} {
    "test": ["test1", "test2", "test3"],
    "teston": "teston2",
    "debug": {}
}
<?php
foreach($this->params as $key=>$val)
{
  $this->rawRequest .= "&$key=$val";
}
?>
我在其他站点获取json数据,jsonlint已经通知json无效

Error: Parse error on line 5:
...n2", "debug": {}} {  "test": ["test1",
---------------------^
Expecting 'EOF', '}', ',', ']', got '{'
我必须做什么才能让我的脚本工作

编辑:在我添加
var\u dump($result)之后it输出:

string(1204) "{
    "test": ["test1", "test2", "test3"],
    "teston": "teston2",
    "debug": {}
} {
    "test": ["test1", "test2", "test3"],
    "teston": "teston2",
    "debug": {}
}"
我将使用以下代码从XML转换json:

<?php
$result = $this->rawResponse;
$config = Array(
    'input-xml' => 1,
);
$repairitfirst = tidy_repair_string($result, $config);
$willbearray = json_encode(simplexml_load_string($repairitfirst));
$jsonfromxml = $willbearray;
?>

我的php转换代码有问题吗? 在我的脚本中,包含如下循环:

<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://example.com/?weather=USA");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec ($ch);
$row = json_decode($result, TRUE);
echo $row['teston'];
?>
{
    "test": ["test1", "test2", "test3"],
    "teston": "teston2",
    "debug": {}
} {
    "test": ["test1", "test2", "test3"],
    "teston": "teston2",
    "debug": {}
}
<?php
foreach($this->params as $key=>$val)
{
  $this->rawRequest .= "&$key=$val";
}
?>


如何在没有循环的情况下$this->params as$key=>$val?可能吗?

执行
var\u转储($result)
并使用已编辑的输出更新您的问题,感谢服务返回格式错误的
json
,它是公共api还是在您的控制下?json对象链接不正确。一个对象结束后应该有一个“,”。这应该在启动curl请求的服务器端处理。听起来你需要联系服务器,然后告诉他们他们发送的json无效。执行
var_dump($result)
并使用已编辑的输出更新您的问题,感谢服务返回格式错误的
json
,它是公共api还是在您的控制下?json对象链接不正确。一个对象结束后应该有一个“,”。这应该在启动curl请求的服务器端进行处理。听起来您需要联系服务器,然后告诉他们发送的json无效。