Home  >  Article  >  Java  >  jsonArray traversal takes out the objects in the array

jsonArray traversal takes out the objects in the array

巴扎黑
巴扎黑Original
2016-12-02 10:37:212995browse

 List<String> helpPersonList=new ArrayList<>();
                List<String> oraList=new ArrayList<>();
                String json="[{"aid":"aid-0035","aidName":"贾线柳","aidType":"1","organization":"镇财政分局"}]";
                JSONArray jsonArray=JSONArray.fromObject(json);
                for (int j= 0;j<jsonArray.size();j++){
                     JSONObject jsonObject=jsonArray.getJSONObject(j);
                    String aidName=jsonObject.getString("aidName");
                    String org=jsonObject.getString("organization");
                    if(jsonArray.size()==1){
                        helpPersonList.add(aidName);
                    }else{
                        helpPersonList.add(aidName+"("+povertys.get(i).getPoorName()+")");
                    }
                    oraList.add(org);
                }

Convert string to JSONArray and then traverse the array



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn