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方法解决了它。

更多相关文章

  1. 解析错误:语法错误,E:\xampp\htdocs\online\viewhistory >中
  2. PHP XAMPP配置PHP环境和Apache80端口被占用解决方案
  3. PHP实现接口方法时出现致命错误
  4. JSON解析错误:无法识别的标记'<'处于角度
  5. 在提交注册表单时使用jQuery显示错误
  6. 获取所有网站的错误,[重复]
  7. 如何让jQuery ajax执行错误功能
  8. Yii 访问 Gii(脚手架)时出现 403 错误
  9. PHP强大包括处理错误?

随机推荐

  1. C#中关于程序功能实现以及对代码选择的思
  2. 介绍asp.net MVC下使用rest的方法
  3. C#中的抽象类与接口的详解
  4. ASP.NET MVC 使用Bootstrap方法介绍
  5. Asp.net Core应用程序在Linux上部署的图
  6. .NetCore如何获取Json和Xml格式的配置信
  7. ASP.Net Core中关于WebApi几种版本控制对
  8. 详解.Net Core使用Socket与树莓派进行通
  9. C#实现表格隔行换色
  10. .NET Core中遇到的一些坑的图文详解