Java获取{ "retCode": "000000", "retDesc": "成功", "data": { "pageNo": 1, "pageSize": 500, "count": 12712, "totalPage": 26, "first": 0, "last": 0, "prev": 0, "next": 0, "firstPage": false, "lastPage": false, "list": [ { "orgaCodeName": "学校标识码", "recommendUseCount": 0, "areaName": "安徽省", "provinceCode": "340000", "orgaId": "34d8a1b4b51b434998a1b4b51b034954", "orgaCode": "12341203MB1J665277", "zyappCount": 0, "orgaName": "颍东区向阳小学", "orgaLogo": "", "askUseCount": 0 }, { "orgaCodeName": "学校标识码", "recommendUseCount": 0, "areaName": "安徽省", "provinceCode": "340000", "orgaId": "9e68dc5aa2b441b4a8dc5aa2b401b4fc", "orgaCode": "12340207MB1H12340F", "zyappCount": 0, "orgaName": "芜湖市皖江小学", "orgaLogo": "", "askUseCount": 0 } ] } }json串中的所有orgaName
时间: 2023-05-12 17:06:11 浏览: 77
您可以使用以下代码来获取json串中的所有orgaName:
import org.json.JSONArray;
import org.json.JSONObject;
public class Main {
public static void main(String[] args) {
String jsonStr = "{\"retCode\":\"000000\",\"retDesc\":\"成功\",\"data\":{\"pageNo\":1,\"pageSize\":500,\"count\":12712,\"totalPage\":26,\"first\":0,\"last\":0,\"prev\":0,\"next\":0,\"firstPage\":false,\"lastPage\":false,\"list\":[{\"orgaCodeName\":\"学校标识码\",\"recommendUseCount\":0,\"areaName\":\"安徽省\",\"provinceCode\":\"340000\",\"orgaId\":\"34d8a1b4b51b434998a1b4b51b034954\",\"orgaCode\":\"12341203MB1J665277\",\"zyappCount\":0,\"orgaName\":\"颍东区向阳小学\",\"orgaLogo\":\"\",\"askUseCount\":0},{\"orgaCodeName\":\"学校标识码\",\"recommendUseCount\":0,\"areaName\":\"安徽省\",\"provinceCode\":\"340000\",\"orgaId\":\"9e68dc5aa2b441b4a8dc5aa2b401b4fc\",\"orgaCode\":\"12340207MB1H12340F\",\"zyappCount\":0,\"orgaName\":\"芜湖市皖江小学\",\"orgaLogo\":\"\",\"askUseCount\":0}]}}";
JSONObject jsonObj = new JSONObject(jsonStr);
JSONArray orgaList = jsonObj.getJSONObject("data").getJSONArray("list");
for (int i = 0; i < orgaList.length(); i++) {
String orgaName = orgaList.getJSONObject(i).getString("orgaName");
System.out.println(orgaName);
}
}
}
这段代码将输出以下内容:
颍东区向阳小学
芜湖市皖江小学
希望这能帮到您!
阅读全文