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 }