0

Following is my response from server, i am able to get clientproduct array but not able to get bulkprice array and its json object. I don't know what the issue is.

{"status":"success","clientproduct":[{"pid":"4","name":"kangan pair","unitprice":"1500","boxqty":"1","bulkprice":[{"minqty":"10","price":"1500"},{"minqty":"15","price":"1470"},{"minqty":"20","price":"1460"}]}]}

code

if(bxqtyy.getText().toString().trim().length() > minimum_qty.toString().equals())
                            {
                                System.out.println("NKDBKDKB");
                            }

Code here

    if (json != null) {
                    try {
                        JSONObject jsonObj = new JSONObject(json.toString());

                        // Getting JSON Array node
                        clientproduct = jsonObj.getJSONArray(CLIENTPRODUCT_LIST);

                        // looping through All Contacts
                        for (int i = 0; i < clientproduct.length(); i++) {
                            ck = clientproduct.getJSONObject(i);

                           unitp=ck.getString("unitprice");
                            System.out.println("Unit ni price"+unitp);

                           boxq=ck.getString("boxqty");
                            System.out.println("Box ni quantity "+boxq);

                            // creating new HashMap
                            /*HashMap<String, String> map = new HashMap<String, String>();

                            // adding each child node to HashMap key => value
                            map.put(UNIT_PRICE, c.getString(UNIT_PRICE));
                            map.put(BOX_QTY,c.getString(BOX_QTY));
                            clientproductdata.add(map);*/

                            if(clientproduct !=null)
                            {
                                bulkprice = ck.getJSONArray(BULKPRICE_LIST);



                                 for (int a = 0; a < bulkprice.length(); a++) {
                                    jo = bulkprice.getJSONObject(a);


                                   /* if(c.getString("boxqty").toString().equals("") == jo.getString("minqty").toString().equals("15"))
                                    {

                                    }*/
                                   minimum_qty=jo.getString("minqty");
                                    System.out.println("MinQuantitiy"+minimum_qty);

                                   pricess=jo.getString("price");
                                    System.out.println("Box price "+pricess);
                                   System.out.println("Bularay"+bulkprice);
                                 }

                            }
                            else
                            {
                                System.out.println("Badluck");
                            }

                        }

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                } else {
                    Log.e("ServiceHandler", "Couldn't get any data from the url");
                }

            runOnUiThread(new  Runnable() 
             {
                @Override
                public void run() 
                {
                    //Toast.makeText(Add_ClientOrder.this, msg, Toast.LENGTH_LONG).show();
                } 
            });
             return json.getString(FEEDBACK_SUCCESS);

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

    // After completing background task Dismiss the progress dialog

    protected void onPostExecute(String file_url) {
        //dismiss the dialog once product deleted
        pDialog.dismiss();
        autoproduct.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                // TODO Auto-generated method stub
                uprice.setText(unitp);
                bxqtyy.setText(boxq);

                bxqtyy.addTextChangedListener(new TextWatcher() {

                    @Override
                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                        if(bxqtyy.getText().toString().trim().length() > minimum_qty.toString().equals("15"))
                            {
                                System.out.println("NKDBKDKB");
                            }
                    }

                    @Override
                    public void beforeTextChanged(CharSequence s, int start, int count,
                            int after) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void afterTextChanged(Editable s) {
                        // TODO Auto-generated method stub

                    }
                });

            }
        });


        //parentcat.getText().clear();
}}
1
  • in place of bulkprice = jsonObj.getJSONArray(BULKPRICE_LIST); you should write bulkprice = c.getJSONArray(BULKPRICE_LIST); Commented Apr 24, 2015 at 6:40

3 Answers 3

1

i am able to get clientproduct array but not able to get array bulkprice array

bulkprice JSONArray is inside JSONObject of clientproduct JSONArray. so use c instead of jsonObj to get bulkprice JSONArray :

bulkprice = c.getJSONArray(BULKPRICE_LIST);
Sign up to request clarification or add additional context in comments.

5 Comments

@chris: Which question ?
@chris: share question url
i have two pagers, in my first pager i have images of product..so now if user swipes image then in second pager i want to display its price
did you check that?
0

Here is my decision:

JSONArray big = jsonObject.getJSONArray("clientproduct");
for(int i = 0; i < big.lenght(); i++) {
    JSONArray little = big.getJSONObject(i).getJSONArray("bulkprice");
}

1 Comment

I am getting bulkarray perfectly,,and here by default i get boxqty 1,now if user enter in edittext 14 then price should remain 1500,and if user enter 15 it should get 1470,but i am not able to get it,what is the issue with this,its not allowing me to do like this
0

Use these code...it can be helpful for you....

JSONArray outer_json_array = RESPONSE.getJSONArray("clientproduct");

for(int i=0;i<outer_json_array .length();i++) {

    JSONArray inner_json_array = outer_json_array.getJSONObject(i).getJSONArray("bulkprice");

    for(int j=0;j<inner_json_array.length();j++) {
    }
}

3 Comments

can you helpppp
@chris what happened??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.