用于匹配的正则表达式如下: ([1-9]d*. ((d* )|(0(.) d*[1-9] ) ) ) ) ) ) ) )
(
[1-9] :匹配1~9的数字;
(d )一致数字,包括0至9;
*d后紧跟着表示与零个以上的数字一致。
()匹配小数点;
?后跟零个或一个小数点;
0 :与一个数字一致的0;
)
其中的[1-9]d*. d用于将非负整数(如*、23、34.0和56.78 )与浮点数匹配。
的0.d*[1-9]用于匹配非负浮点数,如0.1、0.23和0.405。
私有列表
gettmpfieldslist (列表
字段列表,String tmptableName,String IndexName ) {
列表
maps=new ArrayList (;
字符串字段:字段列表(for ) {
//必须包含传入的标识符和数字
if(field.tolowercase ().contains (tmp tablename.to lower case ) ) ) ) 0
字段列表e=new field list (;
string [ ] field array=field.split ((. ); //带数字的字符串
field=field.replaceall('_? d ',''); //加下划线数字有效物理名称
string [ ] field array2=field.split ((. ' ); //无数字字符串
patternp=pattern.compile('d '; //得到字符串中的数字
matcherm=p.matcher (字段阵列[1];
if(m.find () ) )。
intkey=integer.parseint (m.group );
e.setcasevalue (密钥;
if (string utils.is equal (field array2[1],IndexName ) ) { //for BAT203
e.setfield(check_position ); //项目物理名称
}else{
e.setfield (场阵列2 [1]; //项目物理名称
}
e.setfield name (字段阵列[1]; //项目物理名称别名
MAPS.add(e;
}
/**else{只有后面有数字的东西比较好
if (string utils.is equal (field array2[1],IndexName ) ) { //for BAT203
e.setfield(check_position ); //项目物理名称
}else{
e.setfield (场阵列2 [1];
}
e.setfield name (字段阵列[1];
MAPS.add(e;
(*/
}
}
//Add ACE商品() .更新) ) ) )。
返回映射;
}
补充知识: fasterxml-关于痴情柚子发生Can not deserialize instance of异常原因验证
这两天有很多
Java.lang.illegalargumentexception : cannotdeserializeinstanceofjava.util.arraylistoutofstart _ object token
at [Source: N/A; 发生了line: -1,column: -1]错误。
有经验的人一看,就知道对象的属性转换有异常。 为了找出这个错误的根本原因。
只能乘坐代码模拟。
//*
*创建by Changle on 17/1/9。
*/
@Slf4j
公共类JSON test {
publicstaticvoidmain (字符串[ ] args ) {
testAtoB (;
//testAtoB ()发生: cannotdeserializeinstanceofcom.test.JSON test $ hobbyoutofstart _ array token
测试btoa (;
//testBto
A() 发生:Can not deserialize instance of java.util.ArrayList out of START_OBJECT token}
public static void testAtoB(){
List hobbies = new ArrayList<>();
Random random = new Random();
for(int i=0;i<3;i++){
Hobby hobby = new Hobby(random.nextInt(),"测试名称","测试类型",random.nextInt(100));
hobbies.add(hobby);
}
StudentA studentA = new StudentA();
studentA.setAge(23);
studentA.setFromCity(true);
studentA.setMoney(3000);
studentA.setName("bzddt");
studentA.setHobbies(hobbies);
try {
String str = JSON.json(studentA);
log.info("str={}",str);
//list转换单个projo
StudentB studentB = JsonUtil.jsonObject(str, StudentB.class);
log.info("studentB.name:{}",studentB.getName());
} catch (Exception e) {
e.printStackTrace();
}
}
public static void testBtoA(){
Random random = new Random();
Hobby hobby = new Hobby(random.nextInt(), "测试名称", "测试类型", random.nextInt(100));
StudentB studentB2 = new StudentB();
studentB2.setAge(23);
studentB2.setFromCity(true);
studentB2.setMoney(3000);
studentB2.setName("bzddt");
studentB2.setHobbies(hobby);
String str2 = null;
try {
str2 = JSON.json(studentB2);
//单个projo转换list
StudentA studentA2 = JsonUtil.jsonObject(str2, StudentA.class);
log.info("studentB.name:{}", studentA2 == null ? "" : studentA2.getName());
} catch (IOException e) {
e.printStackTrace();
}
}
@Data
public static class StudentA{
private String name;
private int age;
private long money;
private boolean isFromCity;
private List hobbies;
}
@Data
public static class StudentB{
private String name;
private int age;
private long money;
private boolean isFromCity;
private Hobby hobbies;
}
@Data
public static class Hobby{
private long hId;
private String hName;
private String type;
private int score;
public Hobby(){}
public Hobby(long hId,String hName,String type,int score){
this.hId = hId;
this.hName = hName;
this.type = type;
this.score = score;
}
}
}
结论:
Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
该错误是因为目标类属性keyX需要ArrayList类型的,待转换的json串里属性名keyX对应的,不是一个ArrayList集合,而是单个 POJO。
Can not deserialize instance of com.test.JSONTest$Hobby out of START_ARRAY token
该错误是因为目标类属性keyX需要JSONTest$Hobby类型的,待转换的json串里属性名keyX对应的,不是一个POJO对象,而是ArrayList集合。
以上这篇java正则表达式匹配所有数字的案例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。