3 回答

TA貢獻1850條經驗 獲得超11個贊
Android 代碼實際上并未將 JSON 發送到服務器。它使用舊的鍵值表單字段格式,無法表示復雜的對象。要解決此問題,請將 Android 代碼更改為使用,JsonObjectRequest而不是StringRequest,并將請求作為 傳遞JSONObject:
JSONObject params = new JSONObject();
params.put("subject",subject);
params.put("class",qSet[qsetCntr][0]);
params.put("user", thisuser);
params.put("result", new JSONArray(resltn));
params.put("qstn", new JSONArray(qstnn));
params.put("qid", new JSONArray(qiddn));
params.put("ans", new JSONArray(answn));
params.put("lickey","jg2ler3xvbdgsjkru12tutujghgjgl4jkjojuir8uttzcdadasretf");
reqPostanswers = new JsonObjectRequest(Request.Method.POST, urll, params,
? ? new? Response.Listener<String>() { ... },
? ? new Response.ErrorListener() { ... }
});
完成此更改后,您很可能還必須更改 PHP 代碼,以便它從請求正文中讀取 JSON。

TA貢獻1895條經驗 獲得超7個贊
首先問題出在你創建的json上。Json 數組應如下所示,
"qstn": ["607421_15958169393.JPG","410816_15958169444.JPG",
"655502_15958169495.JPG","625421_15958179086.JPG","625421_15958179086.JPG",
"461984_15958180457.JPG"]
按照上面所示的方式轉換你的 json 數組并在 php 端使用,
$model = json_decode($json,true);
現在您可以訪問該變量的值,如下所示:
$class = $model["class"];
//The 0th index of qstn array can be accessed as
$qsnt1 = $model["qstn"][0];
為了避免將來出現此類錯誤,請使用gson為您創建 json。

TA貢獻1777條經驗 獲得超10個贊
使用ltrim和函數從字符串中rtrim刪除 和[,然后使用explode可以將字符串轉換為數組。]注意:此示例僅在分隔符為,空格 ( ", ")時有效
例如"qstn":
$array = json_decode($json, true);
$resultArray = explode(", ",rtrim(ltrim($array["qstn"],"["),"]"));
var_dump($resultArray);
- 3 回答
- 0 關注
- 172 瀏覽
添加回答
舉報