从android发送数组,在PhP服务器上使用截击进行接收

从android发送数组,在PhP服务器上使用截击进行接收,php,android,arrays,android-volley,Php,Android,Arrays,Android Volley,嗨,我想发送一个字符串值数组到PhP服务器,PhP解码并将它们存储在PhP变量中 这是我在安卓工作室的代码 private void getEventDetailRespond(RequestQueue requestQueue) { JSONObject params = new JSONObject(); try { for (int i=0; i <eventIDBeacon.size();i++){

嗨,我想发送一个字符串值数组到PhP服务器,PhP解码并将它们存储在PhP变量中

这是我在安卓工作室的代码

private void getEventDetailRespond(RequestQueue requestQueue) {
        JSONObject params = new JSONObject();
        try {
            for (int i=0; i <eventIDBeacon.size();i++){
                params.put(Config.EVENT_ID, eventIDBeacon.get(i));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        //Creating a JSONObject request
        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST,Config.DATA_URL,params.toString(),
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject respond) {
                            try {
                                Toast.makeText(Beacon_MainActivity.this,"eventDetail respond "+respond.toString(),Toast.LENGTH_LONG).show();
                                eventArray = new JSONArray();
                                eventDetail = new ArrayList<>();
                                eventArray = respond.getJSONArray("result");
                                eventDetail = getEventDetail(eventArray);

                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                            Toast.makeText(Beacon_MainActivity.this, "Unable to fetch data event Detail: " +error.getMessage(),Toast.LENGTH_LONG).show();
                        }
                    }
                );

        //Adding request to the queue
        requestQueue.add(jsonObjectRequest);

    }

    private ArrayList getEventDetail(JSONArray j) {
        ArrayList event = new ArrayList();
        //Traversing through all the items in the json array
        for (int i = 0; i < j.length(); i++) {
            try {
                //Getting json object
                JSONObject json = j.getJSONObject(i);

                //Adding the name of the event to array list
                event.add(json.getString(Config.EVENT_TITLE));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        if (event.isEmpty()) eventView.setVisibility(View.INVISIBLE);
        else {
            if (beacons.size()!=0) {
                checkIn.setVisibility(View.VISIBLE);
                eventView.setVisibility(View.VISIBLE);

                spinner.setAdapter(new ArrayAdapter<String>(Beacon_MainActivity.this, android.R.layout.simple_spinner_dropdown_item, event));
            }else {
                checkIn.setVisibility(View.INVISIBLE);
                eventView.setVisibility(View.INVISIBLE);
            }

        }
        return event;
    }
private void GetEventDetailResponse(请求队列请求队列){
JSONObject参数=新的JSONObject();
试一试{

对于(inti=0;i您必须在getEventDetailRespond方法中重写volley的getParams方法

 @Override
protected Map<String, String> getParams() throws com.android.volley.AuthFailureError {
 JSONObject params = new JSONObject();
    try {
        for (int i=0; i <eventIDBeacon.size();i++){
            params.put(Config.EVENT_ID, eventIDBeacon.get(i));
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
return params;
};
@覆盖
受保护的映射getParams()抛出com.android.volley.AuthFailureError{
JSONObject参数=新的JSONObject();
试一试{

对于(inti=0;iArrayList中对象的第一个:创建JSONObjectmethod名称作为getJSONObject,如下所示

public class EstimateObject {
String id, name, qty, price, total;
public EstimateObject(String id, String name, String qty, String price, String total, int position)
{
    this.id = id;
    this.name = name;
    this.qty = qty;
    this.price = price;
    this.total =total;
    this.position = position;
}
 public JSONObject getJSONObject() {
    JSONObject obj = new JSONObject();
    try {
        obj.put("Id", id);
        obj.put("Name", name);
        obj.put("Qty",qty);
        obj.put("Price", price);
        obj.put("Total", total);
    }
    catch (JSONException e) {
        e.printStackTrace();
    }
    return obj;
}
下面是我在活动中如何转换它的

    JSONObject JSONestimate = new JSONObject();
    JSONArray myarray = new JSONArray();

    for (int i = 0; i < items.size(); i++) {

        try {
            JSONestimate.put("data:" + String.valueOf(i + 1), items.get(i).getJSONObject());
            myarray.put(items.get(i).getJSONObject());

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    Log.d("JSONobject: ", JSONestimate.toString());
    Log.d("JSONArray : ", myarray.toString());
在php中

$json = $_POST['jsonarray'];
$json_array = json_decode($json,true);

非常感谢,但是如何在PhP服务器上解码并将值存储到PhP数组中?是否要将“$post”变量存储到PhP数组中?是的,我的目标是将ArrayList(eventBeacon)发送到PhP服务器并存储到本地PhP变量中。我仍然不知道如何发送和接收and数组(1个变量可以)之后,$post变量包含一个json数组……您可以使用var_dump($post)来记录发送到服务器的内容非常感谢将var_dump($post)放在何处以及如何查看日志?
    JSONObject JSONestimate = new JSONObject();
    JSONArray myarray = new JSONArray();

    for (int i = 0; i < items.size(); i++) {

        try {
            JSONestimate.put("data:" + String.valueOf(i + 1), items.get(i).getJSONObject());
            myarray.put(items.get(i).getJSONObject());

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    Log.d("JSONobject: ", JSONestimate.toString());
    Log.d("JSONArray : ", myarray.toString());
map.put("jsonarray",myarray.toString());
$json = $_POST['jsonarray'];
$json_array = json_decode($json,true);