Regex 使用具有正则表达式的字符串初始化json对象
我想用给定的字符串初始化json对象Regex 使用具有正则表达式的字符串初始化json对象,regex,json,Regex,Json,我想用给定的字符串初始化json对象 String str = "{regex:/^(a-z|A-Z|0-9)*[^:*()#%`~*^&+={}| >"|\\]*$/,'value':10}"; try { JSONObject jsonObj = new JSONObject(str); System.out.println("Result ######### "+jsonObj); } catch (JSONException e) {
String str = "{regex:/^(a-z|A-Z|0-9)*[^:*()#%`~*^&+={}| >"|\\]*$/,'value':10}";
try {
JSONObject jsonObj = new JSONObject(str);
System.out.println("Result ######### "+jsonObj);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
它显示错误是因为键正则表达式的特殊字符,是否有其他可能实现此目的 尝试在您的
regEx
周围添加单引号
String str = "{regex:'/^(a-z|A-Z|0-9)*[^:*()#%`~*^&+={}| >"|\\]*$/','value':10}";
这个字符串不是,JSON不知道/…/
是什么意思。