【发布时间】:2020-01-09 10:25:02
【问题描述】:
我找不到答案。试过很多网站,包括这个。我想知道问题出在哪里。
错误是:org.json.JSONException:java.lang.String 类型的值连接无法转换为 JSONObject
这是我的安卓代码:-
StringRequest stringRequest=new StringRequest(Request.Method.POST, URL_LOGIN,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject=new JSONObject(response);
String success=jsonObject.getString("success");
JSONArray jsonArray=jsonObject.getJSONArray("login");
if (success.equals("1")){
for (int i=0;i<jsonArray.length();i++) {
JSONObject object=jsonArray.getJSONObject(i);
String uname=object.getString("username").trim();
String email=object.getString("email");
Toast.makeText(MainActivity.this, "Login Successful!!! \n Your Name: "+uname+"\nYour Email: "+email, Toast.LENGTH_SHORT).show();
loading.setVisibility(View.GONE);
}
}
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(MainActivity.this," Error!!"+e.toString(),Toast.LENGTH_LONG).show();
loading.setVisibility(View.GONE);
signin_btn.setVisibility(View.VISIBLE);
}
}
},
Logcat
2019-09-06 19:40:37.264 7944-7944/com.example.project W/System.err: org.json.JSONException:java.lang.String 类型的值连接 无法转换为 JSONObject 2019-09-06 19:40:37.264 7944-7944/com.example.project W/System.err:在 org.json.JSON.typeMismatch(JSON.java:111) 2019-09-06 19:40:37.264 7944-7944/com.example.project W/System.err:在 org.json.JSONObject.(JSONObject.java:160) 2019-09-06 19:40:37.264 7944-7944/com.example.project W/System.err: at org.json.JSONObject.(JSONObject.java:173)
【问题讨论】:
-
显示您的 json 响应。
-
你能显示响应字符串吗?
标签: java android json phpmyadmin localhost