簡體   English   中英

PHP從Android studio volley Get請求接收JSON對象

[英]PHP receive JSON object from Android studio volley Get request

我正在使用 Android studio 使用 volley 發送 GET 請求。 我包括一個 HashMAP 參數(稱為 whereArray)。 我來自 volley 請求的 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 中解碼參數和循環遍歷結果數組的幫助將不勝感激。

謝謝

{country_name=Botswana, region=Southern Africa}不是有效的 JSON,它應該是{"country_name": "Botswana", "region": "Southern Africa"}

另外, json_decode()默認返回一個對象,而不是數組,如果你想要一個數組,你需要傳遞true作為第二個參數: json_decode($whereArray, true)

請參閱文檔: PHP json_decode()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM