Home > Java > javaTutorial > body text

jsonArray traversal takes out the objects in the array

巴扎黑
Release: 2016-12-02 10:37:21
Original
3003 people have browsed it

 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);
                }
Copy after login

Convert string to JSONArray and then traverse the array



Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template