开发者技术变现资源聚集地
https://www.baiydu.com
好久没写日志了,今天来写一个,JSONArry fro循环判断value,移除不需要的,不需再将JSONArry再次转换成 map或list。
JSONArray移除成员只能通过for遍历取成员,判断后remove(index),这样很明显是不行的,除非移除的成员只有1个,否则再你移除后for循环的遍历次数就被打乱了。你就会移除到不需要移除的成员。处理这个问题的方式其实很多的,比如创建list范型map将json遍历后一个一个弄到他们里面去......
我这里说的方式不需要创建LIST,MAP 直接就是用 remove和原本的JSONArry实现,并且效率应该是最高的。
parameterArray=“[{"boundingBox":"29,28,401,29,399,85,27,84","words":[{"boundingBox":"29,28,70,29,68,85,27,84","word":"好"},{"boundingBox":"84,29,111,29,109,85,82,85","word":"友"},{"boundingBox":"125,30,401,29,399,85,123,86","word":"137*8288"}],"text":"好友137*8288"},{"boundingBox":"799,25,1018,29,1016,91,797,87","words":[{"boundingBox":"799,25,931,25,929,87,797,87","word":"10,090"},{"boundingBox":"945,25,960,25,958,87,943,87","word":"金"},{"boundingBox":"975,25,1018,29,1016,91,973,87","word":"币"}],"text":"10,090金币"},{"boundingBox":"25,123,279,127,277,174,23,170","words":[{"boundingBox":"36,124,71,127,69,174,34,171","word":"02"},{"boundingBox":"82,127,94,128,92,175,80,174","word":"月"},{"boundingBox":"106,128,140,128,138,175,104,175","word":"21"},{"boundingBox":"152,129,164,128,162,175,150,176","word":"日"},{"boundingBox":"187,128,279,127,277,174,185,175","word":"18:50"}],"text":"02月21日 18:50"},{"boundingBox":"621,123,1017,124,1015,176,619,175","words":[{"boundingBox":"633,122,659,123,657,175,631,174","word":"等"},{"boundingBox":"672,124,697,124,695,176,670,176","word":"待"},{"boundingBox":"710,123,723,124,721,176,708,175","word":"发"},{"boundingBox":"736,124,761,124,759,176,734,176","word":"放"},{"boundingBox":"774,124,800,124,798,176,772,176","word":"奖"},{"boundingBox":"813,124,825,124,823,176,811,176","word":"励"},{"boundingBox":"838,124,928,124,926,176,836,176","word":"0"},{"boundingBox":"941,124,966,124,964,176,939,176","word":"市"},{"boundingBox":"979,124,1017,124,1015,176,977,176","word":"市"}],"text":"等待发放奖励0市市"}]”;
int tempLowTimes=-1; for(int k=0;k< parameterArray.length();k++) { JSONObject singlexx= parameterArray.getJSONObject(k); String dltTxt=singlexx.getString("text").replace(" ", ""); if (dltTxt.contains("等待发")) { parameterArray.remove(k); k=tempLowTimes; continue; } if (dltTxt.contains("月")&&dltTxt.contains("日")) { parameterArray.remove(k); k=tempLowTimes; continue; } tempLowTimes=tempLowTimes+1; }
本人做的一款androidApp, 下载量已经有2000多万,各种当前热门的网络手机奖励红包全部集成,另外还有热门电影和淘宝高额优惠券!很适合各类型的用户。