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

带注释的json反序列化失败 #939

Closed
lmm1990 opened this issue Dec 7, 2016 · 9 comments
Closed

带注释的json反序列化失败 #939

lmm1990 opened this issue Dec 7, 2016 · 9 comments
Labels
Milestone

Comments

@lmm1990
Copy link

lmm1990 commented Dec 7, 2016

{
"isDebug":true/*调试状态*/
}

github星号显示不出来

@CharkeyQK
Copy link
Contributor

CharkeyQK commented Dec 7, 2016

public static void main(String[] args) {
        String jsonString = "" +
                "{" +
                "    \"age\": 25,/*comment*/" +
                "    \"name\": \"charkey\"" +
                "}";
        TestUser testUser = JSONObject.parseObject(jsonString, TestUser.class);
        System.out.println(testUser);
    }

测试ok,不过一般也不会有注释吧
1.2.21

@lmm1990
Copy link
Author

lmm1990 commented Dec 8, 2016

public static void main(String[] args) {
        String jsonString = "" +
                "{" +
                "    \"age\": 25," +
                "    \"is_stop\":false/*comment*/" +
                "}";
        TestUser testUser = JSONObject.parseObject(jsonString, TestUser.class);
        System.out.println(testUser);
    }

测试不ok
1.2.21

@wenshao
Copy link
Member

wenshao commented Dec 9, 2016

你这种注释很奇怪哦

@lmm1990
Copy link
Author

lmm1990 commented Dec 9, 2016

正常的注释呀,js执行:console.log({"is_stop":true/comment/}.is_stop),正常

@lmm1990
Copy link
Author

lmm1990 commented Dec 9, 2016

正则匹配下/星....星/,先去掉注释,再解析json就不会有这样的问题了

@CharkeyQK
Copy link
Contributor

你是不是 false 后面直接跟着注释

false/*comment*/

@lmm1990
Copy link
Author

lmm1990 commented Dec 9, 2016

对的,我打星号怎么被屏蔽了

@wuwen5
Copy link
Contributor

wuwen5 commented Dec 9, 2016

@lmm1990 可以使用markdown标记。
可以参考这个 https://github.com/LearnShare/Learning-Markdown/blob/master/article/extension/code-blocks-and-highlighting.md

与原来使用缩进来添加代码块的语法不同,这里使用 ``` ``` 来包含多行代码:

/*xxx*/

@lmm1990
Copy link
Author

lmm1990 commented Dec 9, 2016

false/comment/ 我要的是单行注释

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants