2015-04-24 2 views
0

Ниже приводится мой ответ от сервера, я могу получить массив clientproduct, но не смог получить массив bulkprice и его объект json. Я не знаю, в чем проблема.Как получить доступ к массиву JSON внутри массива JSON?

{"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"}]}]} 

код

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

Код здесь

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(); 
}} 
+0

вместо 'bulkprice = jsonObj.getJSONArray (BULKPRICE_LIST);' вы должны написать 'bulkprice = c.getJSONArray (BULKPRICE_LIST);' –

ответ

1

я могу получить clientproduct массив, но не в состоянии получить массив массив bulkprice

bulkprice JSONArray находится внутри JSONArray. поэтому используйте c вместо jsonObj, чтобы получить bulkprice JSONArray:

bulkprice = c.getJSONArray(BULKPRICE_LIST); 
+0

yup its working..thanks – chris

+0

@chris: Какой вопрос? –

+0

@chris: share question url –

0

Вот мое решение:

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

Я получаю bulkarray отлично, и здесь по умолчанию я получаю boxqty 1, теперь, если пользователь вводит в edittext 14, тогда цена должна оставаться 1500, а если пользователь вводит 15, он должен получить 1470, но я не могу его получить, что это вопрос с этим, его не позволяет мне делать вот так: – chris

0

Используйте эти символы ... это может быть полезно для вас ....

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++) { 
    } 
} 
+0

вы можете помочь pppp – chris

+0

@chris что случилось ??? –

+0

http://stackoverflow.com/questions/41217237/viewpager-not-getting-last-item – chris

Смежные вопросы