Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使用截取解析JSON_Android_Json_Android Volley_Jsonobjectrequest - Fatal编程技术网

Android 如何使用截取解析JSON

Android 如何使用截取解析JSON,android,json,android-volley,jsonobjectrequest,Android,Json,Android Volley,Jsonobjectrequest,我正在使用volley库通过api发布数据…这里的内容类型是“application/json” 如何实现这种类型的json数据: URL: Base_URL + dorequisition { "submitted_by_employee_id": 1, "name": "Technolive SF for TC", "bags_thana_wise": [ { "tiger": "10000",

我正在使用volley库通过api发布数据…这里的内容类型是“application/json”

如何实现这种类型的json数据:

URL: Base_URL + dorequisition
{
  "submitted_by_employee_id": 1,
  "name": "Technolive SF for TC",
  "bags_thana_wise":    [
              {
                "tiger": "10000",
                "extreme": "5000",
                "opc": "3000",
                "three_rings": "4000",
                "buffalo_head": "2000", 
               },
            ],

  "free_bag": "500",
  "landing_price": "450",
  "transport_cost_ex_factory_rate": "450",
  "amount_taka": "four hundred fifty",
  "bank_name": "IFIC Bank Limited",
  "delivery_point": "Banani",
  "upto_today": "450",
  "bag_type": "swing",
  "remark": "Good Cement",
  "token": "2cbf1cefb6fe93673565ed2a0b2fd1a1"
}
api实现示例:

  public void APIRetailVisitInfo() {

        for (int i = 0; i < retailVisitInfoList.size(); i++) {
            System.out.println("token id:::" + token + "   :::"+employee_id);

            Map<String, String> jsonParams = new HashMap<String, String>();

            jsonParams.put("submitted_by_employee_id", employee_id);
            jsonParams.put("retailer_name", retailVisitInfoList.get(i).getRetails_name());
            jsonParams.put("retailer_phone", retailVisitInfoList.get(i).getRetailer_contact_no());
            jsonParams.put("retailer_address", retailVisitInfoList.get(i).getRetails_address());
            jsonParams.put("remarks", retailVisitInfoList.get(i).getRemarks());
            jsonParams.put("token", token);


            JsonObjectRequest myRequest = new JsonObjectRequest(
                    Request.Method.POST,
                    "http://technolive.co/retailvisitinfo",
                    new JSONObject(jsonParams),

                    new Response.Listener<JSONObject>() {
                        @Override
                        public void onResponse(JSONObject response) {


                            try {
                                code = response.getString("code");
                                //token = response.getString("token");
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }


                            if (code.equals("200")) {

                                System.out.println("APICompetetorBasedOnMArketPrice:::" + code + "   :::");
                            }


                            //  System.out.println("token:::" + token+"   :::");*/
                            //   verificationSuccess(response);

                            System.out.println("APICompetetorBasedOnMArketPrice:::" + response + "   :::");

                        }
                    },
                    new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            //  verificationFailed(error);
                        }
                    }) {

                @Override
                public Map<String, String> getHeaders() throws AuthFailureError {
                    HashMap<String, String> headers = new HashMap<String, String>();

                    String auth = token;
                    headers.put("Content-Type", "application/json; charset=utf-8");
                    headers.put("User-agent", "My useragent");
//                headers.put("Authorization", auth);
                    return headers;
                }


            };

            RequestQueue requestQueue = Volley.newRequestQueue(RetailVisitInfoActivity.this);
            requestQueue.add(myRequest);
            //  MyApplication.getInstance().addToRequestQueue(myRequest, "tag");

        }
    }
public void apiratevisitinfo(){
对于(int i=0;i

有人能帮我吗?…这很简单。首先让我们从袋子开始。bags_thana_wise是一个JSONArray。它包含一个对象。因此,让我们创建对象

JSONObject json1 = new JSONObject();
json1.put("tiger","10000";
json1.put("extreme","5000";
以此类推..现在将这个json对象放入一个数组中

JSONArray jsonArray = new JSONArray();
jsonArray.put(json1);
现在只需将此数组和其他值添加到另一个json对象

JSONObject finalObject = new JSONObject();
finalObject.put("submitted_by_employee_id","1");
finalObject.put("name","Technolive SF for TC");
//put the jsonArray 
finalObject.put("bags_thana_wise",jsonArray);
finalObject.put("free_bag","500");
.
.
.
finalObject.put("token","2cbf1cefb6fe93673565ed2a0b2fd1a1");
现在发出以下截击请求

JsonObjectRequest jsonReq = new JsonObjectRequest(Request.Method.POST,
            myURL, null, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject response) {
          //Handle response
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(PopupActivity.this,"Can not reach server",Toast.LENGTH_LONG).show();
        }

    }){
        @Override
        public String getBodyContentType(){
            return "application/json; charset=utf-8";
        }

        @Override
        public byte[] getBody() {
            try {
                return finalObject == null ? null: finalObject.getBytes("utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return null;
            }
        }
    };

    RequestQueue requestQueue = Volley.newRequestQueue(RetailVisitInfoActivity.this);
        requestQueue.add(jsonRequest);
JsonObjectRequest jsonReq=新的JsonObjectRequest(Request.Method.POST,
myURL,null,新响应。侦听器(){
@凌驾
公共void onResponse(JSONObject响应){
//处理响应
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
Toast.makeText(PopupActivity.this,“无法到达服务器”,Toast.LENGTH_LONG.show();
}
}){
@凌驾
公共字符串getBodyContentType(){
返回“application/json;charset=utf-8”;
}
@凌驾
公共字节[]getBody(){
试一试{
返回finalObject==null?null:finalObject.getBytes(“utf-8”);
}捕获(不支持的编码异常e){
e、 printStackTrace();
返回null;
}
}
};
RequestQueue RequestQueue=Volley.newRequestQueue(RetailVisitInfoActivity.this);
add(jsonRequest);
@Tamzid Babu尝试发布您的json,它将生成等价的java类结构。