大佬教程收集整理的这篇文章主要介绍了【java 菜鸟自动化实践之三】net.sf.json json递归 删除key和key值,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
import net.sf.json.*; import java.util.Iterator; public class Commons { static String keyss; static Object objectss; @SuppressWarnings("rawtypes") public Object skiptojson(Object expect_json,String skip_values){ if(expect_json instanceof JSONArray){ JSONArray objArray = (JSONArray)expect_json; for (int i = 0; i < objArray.size(); i++) { skiptojson(objArray.get(i),skip_values); } } //如果为json对象 else if(expect_json instanceof JSONObject){ JSONObject jsonObjectss = (JSONObject) expect_json; Iterator itss = jsonObjectss.keys(); while (itss.hasNext()) { keyss = itss.next().toString(); objectss = jsonObjectss.get(keyss); // 如果得到的是数组 if (objectss instanceof JSONArray) { if (keyss.equals(skip_values)) { //删除指定的key和key值 jsonObjectss.discard(skip_values); break; } else{ JSONArray objArray = (JSONArray) objectss; skiptojson(objArray,skip_values); } // 如果key中是一个json对象 else if (objectss instanceof JSONObject) { if (keyss.equals(skip_values)) { //删除指定的key和key值 jsonObjectss.discard(skip_values); break; } else { skiptojson((JSONObject) objectss,skip_values);} } // 如果key中是其他 else { if (keyss.equals(skip_values)) { //删除key和key值 jsonObjectss.discard(skip_values); break; } } } } System.out.println("002key:" + expect_json ); return expect_json; } public static void main(String[] args) throws Exception { //checking_response_data 表示json字符串 SONObject expect_json=JSONObject.fromObject(checking_response_data); System.out.println(">>>>>response_json:"+expect_json); skiptojson(expect_json,"@R_106_10586@l"); } }
以上是大佬教程为你收集整理的【java 菜鸟自动化实践之三】net.sf.json json递归 删除key和key值全部内容,希望文章能够帮你解决【java 菜鸟自动化实践之三】net.sf.json json递归 删除key和key值所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。