Php org.json.JSONException:org.json.JSONArray类型的值[]无法在Android中转换为JSONObject
我得到了这个错误: org.json.JSONException:org.json.JSONArray类型的值[]无法转换为JSONObject 我试图显示一些记录从数据库内的android应用程序根据过滤器。邮递员告诉我正确的结果显示错误。我在第二个应用程序中使用了基本相同的方法,而且效果很好 PHP脚本:Php org.json.JSONException:org.json.JSONArray类型的值[]无法在Android中转换为JSONObject,php,android,json,object,Php,Android,Json,Object,我得到了这个错误: org.json.JSONException:org.json.JSONArray类型的值[]无法转换为JSONObject 我试图显示一些记录从数据库内的android应用程序根据过滤器。邮递员告诉我正确的结果显示错误。我在第二个应用程序中使用了基本相同的方法,而且效果很好 PHP脚本: function findUsers($odkial, $co){ $stmt = $this->con->prepare("SELECT Meno, Rodn
function findUsers($odkial, $co){
$stmt = $this->con->prepare("SELECT Meno, RodneCislo, PIK FROM zamestnanci WHERE $odkial LIKE ?");
$stmt->bind_param("s", $co);
$stmt->execute();
$stmt->bind_result($Meno, $RC, $PIK);
$foundUsers = array();
while($stmt->fetch()){
$user = array();
$user['meno'] = $Meno;
$user['rodnecislo'] = $RC;
$user['pik'] = $PIK;
array_push($foundUsers, $user);
}
return $foundUsers;
}
从编辑文本和微调器获取某些参数的Android代码方法:
public void hladajZaznamy(){
HashMap<String, String> params = new HashMap<>();
String pod = podla.getSelectedItem().toString();
String co = "%"+podlac.getText().toString()+"%";
params.put("PodlaCoho", pod);
params.put("Co", co);
PerformNetworkRequest request = new PerformNetworkRequest(Api.HLADAJ_ZAMESTNANCA, params, CODE_POST_REQUEST);
request.execute();
}
感谢您的建议:)这是因为您要转换为
JSONObject
的响应字符串应为JSONArray
的形式,因此请将出错的行更改为此
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
JSONArray objectArray = new JSONArray();
for (int i = 0; i < objectArray.length(); i++) {
//here you can iterate through the array elements and find respective JSONObject and/or other values.
}
}
@覆盖
受保护的void onPostExecute(字符串s){
super.onPostExecute(s);
JSONArray objectArray=新的JSONArray();
for(int i=0;i
希望这有助于..可能重复的私有void存储记录(JSONArray foundUsers)抛出JSONException{userList.clear();for(int i=0;i
{"error":false,"message":"Zamestnanci uspesne vyhladani","foundUsers":[{"meno":"TESTTEST","rodnecislo":"1111225555","pik":"111111"}]}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
JSONArray objectArray = new JSONArray();
for (int i = 0; i < objectArray.length(); i++) {
//here you can iterate through the array elements and find respective JSONObject and/or other values.
}
}