Php JSONArray中的POST字符串和响应

Php JSONArray中的POST字符串和响应,php,android,json,http-post,android-volley,Php,Android,Json,Http Post,Android Volley,实际上,我遵循了许多与我的问题相关的答案,但没有一个答案是有效的,我只是发布了一个字符串,作为回报,我想要一个json数组 注意:当我运行硬代码脚本时,它非常好,但在脚本中,POST值显示为null 以下是我的Android代码: private void getData(){ Bundle extras=getIntent().getExtras(); final String id = extras.getString("value").toString().trim();

实际上,我遵循了许多与我的问题相关的答案,但没有一个答案是有效的,我只是发布了一个字符串,作为回报,我想要一个json数组

注意:当我运行硬代码脚本时,它非常好,但在脚本中,POST值显示为null 以下是我的Android代码:

 private void getData(){
    Bundle extras=getIntent().getExtras();
    final String id = extras.getString("value").toString().trim();
    JSONObject obj =new JSONObject();

    final ProgressDialog loading = ProgressDialog.show(Categories.this, "Please wait...","Fetching data...",false,false);
    Volley.newRequestQueue(this).add(new JsonRequest<JSONArray>(Request.Method.POST, CATEGORIES_URL, obj.toString(),
                    new Response.Listener<JSONArray>() {
                        @Override
                        public void onResponse(JSONArray response) {
                            loading.dismiss();
                            showList(response);
                        }
                    }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    loading.dismiss();
                    Toast.makeText(getApplicationContext(),
                            "Ooops!,Internet Connection Problem", Toast.LENGTH_LONG).show();

                }
            }) {
                @Override
                protected Map<String, String> getParams() throws AuthFailureError {
                    Map<String, String> params = new HashMap<String, String>();
                    params.put(KEY_ID,id);
                    return super.getParams();
                }

                @Override
                protected Response<JSONArray> parseNetworkResponse(
                        NetworkResponse response) {
                    try {
                        String jsonString = new String(response.data,
                                HttpHeaderParser
                                        .parseCharset(response.headers));
                        return Response.success(new JSONArray(jsonString),
                                HttpHeaderParser
                                        .parseCacheHeaders(response));
                    } catch (UnsupportedEncodingException e) {
                        return Response.error(new ParseError(e));
                    } catch (JSONException je) {
                        return Response.error(new ParseError(je));
                    }
                }
            });

 //   RequestQueue requestQueue = Volley.newRequestQueue(this);
   // requestQueue.add(jsonArrayRequest);


    Toast.makeText(Categories.this,id,Toast.LENGTH_LONG ).show();


}

也许您可以使用HTTPPost来实现这一点。有可能是因为饼干的东西,只需要添加以下内容:

    CookieManager cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    httpPost.setCookieHandler(cookieManager);

希望能有帮助

经过这么多的努力和指导,我的php现在可以工作了

代码:

  <?php
require_once('dbConnect.php');
$json = file_get_contents('php://input');
$stripe_json= json_decode($json, TRUE);
$ida=$stripe_json->id;

$sql= "select title,description,image,price,cid FROM products a where a.cid='".$ida."'";
$res=mysqli_query($con,$sql);
$result = array();

while ($row=mysqli_fetch_array($res)){
        array_push($result,array('title'=>$row['0'],
        'description'=>$row['1'],
        'image'=>$row['2'],
        'price'=>$row['3'],

    ));
    }
    echo json_encode(($result));

    mysqli_close($con);

?>
    <?php
require_once('dbConnect.php');
$json = file_get_contents('php://input');
$stripe_json= json_decode($json);
$ida=$stripe_json->id;

$sql= "select title,description,image,price,cid FROM products a where a.cid='".$ida."'";
$res=mysqli_query($con,$sql);
$result = array();

while ($row=mysqli_fetch_array($res)){
        array_push($result,array('title'=>$row['0'],
        'description'=>$row['1'],
        'image'=>$row['2'],
        'price'=>$row['3'],

    ));
    }
    echo json_encode(($result));

    mysqli_close($con);

?>

它不起作用的原因是以任何方式发送字符串并得到JSONArray响应。我不太确定您想要-->什么,但希望这一个有帮助。我的动机是将id(字符串)发送到我的服务器,并在我的sql查询中使用此id并返回json编码结果(JSONArray)
我只是发布一个字符串
。不,你没有那样做。你发布json。
作为回报,我想要一个json数组
。你可以想要很多。但是你是舒尔吗?服务器将以json响应?
当我运行脚本时,它非常好
。剧本你是说你的java代码吗?很好,它运行得非常完美。
但是在脚本中,后置vaue显示null
。这并不完美。但你的确切意思是什么?为什么要发送空值?一个字也听不懂。
我用$id=$\u POST['id'];但它显示null
。哦,这就是你的意思。是的,那是不存在的。您没有以正常方式发送该值。相反,您发送了json。不要使用json发送参数。