如何解决com.android.volley.parseerror:org.json.jsonexception:java.lang.string类型的值userid无法转换为jsonobject这个错误 [英] How to solve com.android.volley.parseerror: org.json.jsonexception: value userid of type java.lang.string cannot be converted to jsonobject this error
本文介绍了如何解决com.android.volley.parseerror:org.json.jsonexception:java.lang.string类型的值userid无法转换为jsonobject这个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将userid发送到服务器并使用Volley连接和php脚本获取与android中的userid相关的数据但是我得到的错误如下:
I am trying to send userid to server and fetch the data related to the userid in android using Volley connectivity and php script But i am getting Error like :
com.android.volley.ParseError: org.json.JSONException: Value UserId of type java.lang.String cannot be converted to JSONObject
其他错误类似:输入结束字符0
帮我解决问题...
我尝试过的事情:
以下是php文件
other Error Like :End of Input character 0 of
Help me to Solve the problem...
What I have tried:
Below is php file
<?php
require "connect.php";
$userId = $_GET['UserId'];
$query = "SELECT * FROM `executive` WHERE ExecutiveId = '$userId'";
$result = mysqli_query($conn, $query);
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_assoc($result)){
echo json_encode($row);
}
} else {
echo "UserId :".$userId."Not Found";
}
mysqli_close($conn);
?>
以下代码来自android文件
Below code is from android file
public void getExecutiveInfo(){
String url = "https://sampleappdatabase.000webhostapp.com/SmartKids/ExecutiveInfo.php";
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("Reponse", response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("Error Response", error.toString());
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> params = new HashMap<>();
params.put("UserId",UserId);
return params;
}
};
Singleton.getInstance(getApplicationContext()).addToRequestque(jsonObjectRequest);
}
推荐答案
userId =
_GET ['UserId '];
_GET['UserId'];
query =SELECT * FROM`manage` WHERE ExecutiveId ='
query = "SELECT * FROM `executive` WHERE ExecutiveId = '
这篇关于如何解决com.android.volley.parseerror:org.json.jsonexception:java.lang.string类型的值userid无法转换为jsonobject这个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文