PHP从Android studio volley Get请求接收JSON对象

我正在使用 Android Studio 使用 volley 发送 GET 请求。我包括一个 HashMAP 参数(称为 whereArray)。我来自凌空请求的 URL 请求看起来像这样......


https://xxxxxxxx.co.za/api/select_from_fact_sighting.php?whereArray={country_name=Botswana, region=Southern Africa}


我需要在服务器端使用此参数的帮助 - 我想在其中循环遍历它并将其内爆到 sql where 子句中。但我正在努力解码我的 php 脚本中的数组(我假设它应该转换为 Json 对象?)。我已经包含了 php 函数的一个片段,我尝试在其中解码数组。


public function select_from_fact_sighting($whereArray) {


    $jsonArray = json_decode($whereArray);

    $elementCount  = count($jsonArray); ```

$whereArray 中{country_name=Botswana, region=Southern Africa} 的值为但 $jsonArray 中的值为空且 $elementCount 为 0 表示 json 解码数组中没有任何内容。非常感谢在 PHP 中解码参数和遍历结果数组的任何帮助。


谢谢


白板的微信
浏览 132回答 1
1回答

慕尼黑8549860

{country_name=Botswana, region=Southern Africa}不是有效的 JSON,应该是{"country_name": "Botswana", "region": "Southern Africa"}另外,json_decode()默认返回一个对象,而不是数组,如果你想要一个数组,你需要true作为第二个参数传递:json_decode($whereArray, true)请参阅文档:PHP json_decode()
打开App,查看更多内容
随时随地看视频慕课网APP