Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

解析属性第一位是数字时异常 NumberFormatException #1112

Closed
xiushao1024 opened this issue Mar 30, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@xiushao1024
Copy link

commented Mar 30, 2017

##当属性的第一位是数字时(如:345_xiu),JsonPath尝试将属性转换为Integer类型,出现java.lang.NumberFormatException。

我的解决方案是在传入表达式时添加"\"进行转义,伪代码:
String path = "$.xiu.\345_xiu";
JsonPath.eval(jsonOgject , path);

希望有更好的解决方法。

@wenshao wenshao added New Feature bug and removed New Feature labels Mar 30, 2017

@wenshao wenshao added this to the 1.2.31 milestone Mar 30, 2017

wenshao added a commit that referenced this issue Apr 1, 2017

@wenshao

This comment has been minimized.

Copy link
Member

commented Apr 3, 2017

https://github.com/alibaba/fastjson/releases/tag/1.2.31
新版本发布已解决问题,请升级

@wenshao wenshao closed this Apr 3, 2017

@xiushao1024

This comment has been minimized.

Copy link
Author

commented May 11, 2017

你好,最近使用JsonPath解析的时候遇到另一个问题。当json 的属性名为数字并且数值过大时(超过integer.max_value),直接使用JsonPath表达式解析报错。

java.lang.NumberFormatException: For input string: "1234567899999"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:495)
at java.lang.Integer.parseInt(Integer.java:527)

public static void main(String[] args) {
//正常解析
String json1 = "{"articles":{"2147483647":{"XXX":"xiu"}}}";
String path1 = "$.articles.2147483647.XXX";
Object read = JSONPath.read(json1, path1);

            //报错
	String json2 = "{\"articles\":{\"2147483648\":{\"XXX\":\"xiu\"}}}";
	String path2 = "$.articles.2147483648.XXX";
	Object read2 = JSONPath.read(json2, path2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.