How to parse multiple rows with jsonOject

前端 未结 3 1911
有刺的猬
有刺的猬 2021-01-23 15:49

I am fetching data from mysql using php API and i pass results to android with Json_encode but when i populate results to android

3条回答
  •  情话喂你
    2021-01-23 16:37

    You have initialized collection in wrong place, Please have look at following code this may help you

     ArrayList> wordList;
                wordList = new ArrayList>();
    
                for (int i = 0; i < response.length(); i++) {
    
                    try {
    
                        JSONObject jObj = new JSONObject(response);
                        boolean error = jObj.getBoolean("error");
                        // Check for error node in json
                        if (!error) {
    
    
                            // user successfully exist in database
                            JSONObject user = jObj.getJSONObject("user");
                            String paid_amount = user.getString("paid_amount");
                            String parking_duration =
                                    user.getString("parking_duration");
                            String parking_name = user.getString("parking_name");
                            HashMap prodHashMap = new
                                    HashMap();
    
                            prodHashMap.put("paid_amount", paid_amount);
                            prodHashMap.put("parking_duration", parking_duration);
                            prodHashMap.put("parking_name", parking_name);
    
    
                            wordList.add(prodHashMap);
                            ;
    
                            progressBarList.setVisibility(View.GONE);
    
                        }
    
                        userList = wordList ;
                        ShowListData()
    

提交回复
热议问题