我自己遇到了很多问题,请尝试一下!
public class CustomRequest extends Request<JSONObject> {private Listener<JSONObject> listener;private Map<String, String> params;public CustomRequest(String url,Map<String, String> params, Listener<JSONObject> responseListener, ErrorListener errorListener) { super(Method.GET, url, errorListener); this.listener = responseListener; this.params = params;}public CustomRequest(int method, String url,Map<String, String> params, Listener<JSONObject> reponseListener, ErrorListener errorListener) { super(method, url, errorListener); this.listener = reponseListener; this.params = params;}@Overrideprotected Map<String, String> getParams() throws com.android.volley.AuthFailureError { return params;};@Overrideprotected Response<JSONObject> parseNetworkResponse(NetworkResponse response) { try { String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); return Response.success(new JSonObject(jsonString), HttpHeaderParser.parseCacheHeaders(response)); } catch (UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } catch (JSonException je) { return Response.error(new ParseError(je)); }}@Overrideprotected void deliverResponse(JSonObject response) { listener.onResponse(response);}
的PHP
$username = $_POST["username"];$password = $_POST["password"];echo json_enpre($response);
您必须制作一张地图,该地图支持键值类型,然后才能进行齐射。在php中,您将获得$ variable = $ _POST [“
key_from_map”]检索$ variable中的值,然后构建响应并对其进行json_enpre。
这是一个如何查询sql并将答案以JSON回发的php示例
$response["devices"] = array(); while ($row = mysqli_fetch_array($result)) { $device["id"] = $row["id"]; $device["type"] = $row["type"]; array_push($response["devices"], $device); } $response["success"] = true; echo json_enpre($response);
您可以在此处看到响应类型为JSONObject
public CustomRequest(int method, String url,Map<String, String> params, Listener<JSONObject> reponseListener, ErrorListener errorListener)
看一下听众的参数!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)