【问题标题】:Mongodb retrieve correct json from geospatial query phpMongodb从地理空间查询php中检索正确的json
【发布时间】:2015-04-07 13:29:05
【问题描述】:

我正在尝试从此代码中检索正确的 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', '}', ',', ']'

我尝试了不同的方法,但没有找到任何解决方案。有人可以帮助我吗?

【问题讨论】:

    标签: php android json mongodb jsonlint


    【解决方案1】:

    通过链接验证和共享数据的工具之一,请使用此工具进行验证,如果无效,请在此处分享或分享给您的朋友以获取帮助http://codebeautify.org/jsonvalidate

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-07
      • 2019-09-23
      • 2017-01-25
      • 1970-01-01
      • 2011-08-04
      • 1970-01-01
      • 2012-02-02
      • 1970-01-01
      相关资源
      最近更新 更多