我正在尝试从此代码中检索正确的 JSON。
$query = array( 'loc' => array('$geoWithin' => array('$centerSphere' => array(array($x,$y), 35 / 6371) )));
$cursor = $collection->find($query);
// How many results found
$num_docs = $cursor->count();
if( $num_docs > 0 )
{
foreach($cursor as $doc['punti'])
echo json_encode($doc);
}
}
else
{
echo "NO LOCATION \n";
}
如果我尝试在http://jsonlint.com/中验证结果,它会显示错误。
我将发布查询结果:
{
"punti": {
"_id": {
"$id": "551fb585ecba12c819000032"
},
"nome": "Google",
"loc": [
-122.083983,
37.422969
],
"icona": 1,
"istituzione_id": {
"$id": "551fb556ecba12c819000031"
}
}
}{
"punti": {
"_id": {
"$id": "5520fe2becba12c003000029"
},
"nome": "Oracle",
"loc": [
-122.262168,
37.531595
],
"icona": 1,
"istituzione_id": {
"$id": "551fb556ecba12c819000031"
}
}
}
JSONLint 中的错误是关于:
Parse error on line 16:
...1" } }}{ "punti": {
--------------------^
Expecting 'EOF', '}', ',', ']'
我尝试了不同的方法,但没有找到任何解决方案。有人可以帮助我吗?