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无效。