Android-Json到arraylist,org.json.JSONException org.json.JSON.typeMismatch(JSON.java:111)
16lz
2021-01-22
Error:
错误:
org.json.JSONException: Value [{"username":"ghs"}] of type java.lang.String cannot be converted to JSONObject W/System.err: at org.json.JSON.typeMismatch(JSON.java:111)
org.json.JSONException:java.lang.String类型的值[{“username”:“ghs”}]无法转换为JSONObject W / System.err:at org.json.JSON.typeMismatch(JSON.java:111 )
Code at android end:
android端的代码:
public void listdrawer(){
onlineList_uname = new ArrayList<>();
try {
JSONObject jsonResponse = new JSONObject(jsonResult);
JSONArray jsonMainNode = jsonResponse.getJSONArray("username");
for (int i = 0; i < jsonMainNode.length(); i++) {
JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);
String name = jsonChildNode.optString("username");
onlineList_uname.add(i,name);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
php end:
php结束:
<?php
require "conn.php";
$sql = "select b.username from l_s a,user_table b where a.user_id=b.user_id and status = 1";
$result = $conn->query($sql);
if ($result->num_rows >0) {
// output data of each row
while($row[] = $result->fetch_assoc()) {
$tem = $row;
$json = json_encode($tem);
}
} else {
echo "0 results";
}
echo json_encode($json);
$conn->close();
?>
2 个解决方案
#1
0
Try:
尝试:
jsonChildNode.optString("username").toString();
I think I had the same issue before and toString method solved it.
我想之前我遇到过同样的问题,toString方法解决了它。
更多相关文章
- 解析错误:语法错误,E:\xampp\htdocs\online\viewhistory >中
- PHP XAMPP配置PHP环境和Apache80端口被占用解决方案
- PHP实现接口方法时出现致命错误
- JSON解析错误:无法识别的标记'<'处于角度
- 在提交注册表单时使用jQuery显示错误
- 获取所有网站的错误,[重复]
- 如何让jQuery ajax执行错误功能
- Yii 访问 Gii(脚手架)时出现 403 错误
- PHP强大包括处理错误?