taotaohx回复于26日16点31分
不明白你想 想干什么
小样儿回复于26日16点44分
学习
hxhjhw回复于26日16点51分
不是任何东西,用正则就一定效率最高的Java code import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Test { /** * @param args */ public static void main(String[] args) { String json = "{\"installer_id\":\"00000003\",\"installer_name\":\"王五\"," + "\"link_tel\":\"15869137621\",\"team_id\":\"00000002\"," + "\"remark\":\"123a{}a[]a,,,ssas\"}"; Map map = new HashMap(); Pattern p = Pattern.compile("[\\w[^\\[\\],{}]]+"); Matcher m = p.matcher(json.replaceAll("'|\"", "")); String[] _strs = null; while (m.find()) { _strs = m.group().split(":"); if (_strs.length == 2) map.put(_strs[0], _strs[1].trim()); } System.out.println(map); map.clear(); // 去掉前后的大括号后,用逗号分割 String[] jsons = json.substring(1, json.length() - 1).split(","); for (int i = 0; i < jsons.length; i++) { // 片段内用冒号分隔 String[] ps = jsons[i].replace("\"", "").split(":"); if (ps.length == 2) { map.put(ps[0], ps[1]); } } System.out.println(map); } }
kk9525回复于26日17点04分
Java code public static void main(String[] args)throws Exception { String json="{\"installer_id\":\"00000003\",\"installer_name\":\"王五\"," + "\"link_tel\":\"15869137621\",\"team_id\":\"00000002\"," + "\"remark\":\"123a{}a[]a,,,ssas\"}"; Map map = new HashMap(); //Pattern p = Pattern.compile("[\\w[^\\[\\],{}]]+"); Pattern p = Pattern.compile("(?:\"\\w+\"):(?:\"[^\"]+\")"); //Matcher m = p.matcher(json.replaceAll("'|\"", "")); Matcher m = p.matcher(json); String[] _strs = null; while (m.find()) { _strs = m.group().split(":"); if(_strs.length == 2 ) map.put(_strs[0].replaceAll("'|\"", ""), _strs[1].trim().replaceAll("'|\"", "")); } System.out.println(map); }