1 /**Java任意JSON字符串中,包含指定关键词的json值*/ 2 public static void main(String[] s){ 3 String attrjson = "{\"12\":\"100kg\",\"96\":\"sd\"}"; 4 JSONObject obj = (JSONObject) JSON.parse(attrjson); 5 String keyword = "kg"; 6 7 Set<Entry<String, Object>> set = obj.entrySet(); 8 Iterator iterator = set.iterator(); 9 while(iterator.hasNext()){ 10 Object keyObj = iterator.next(); 11 String value = keyObj.toString(); 12 if(StringUtils.isNoneBlank(value) && value.contains(keyword)){ 13 String keyval = value.substring(value.lastIndexOf("=")+1, value.length()); 14 System.out.println(keyval); 15 } 16 } 17 }
原文地址:https://www.cnblogs.com/modairy/p/8182083.html
时间: 2024-10-13 17:31:58