JSONWithPadding的结果最后缺少分号:
JSONWithPadding jsonWithPadding = new JSONWithPadding({"key":"value"}, "cb");
return Response.status(200).entity(jsonWithPadding).build();
预期:
cb({"key":"value"}); --> with semicolon
实际:
cb({"key":"value"}) --> without semicolon
有什么想法吗?
最佳答案
分号没有丢失,在(本示例和)大多数情况下,分号是可选的。因此 JSONWithPadding
类工作正常。
ECMAScript 语言规范定义了 7.9.1 Rules of Automatic Semicolon Insertion ,总结自JavaScript and Semicolons作为
Certain ECMAScript statements (empty statement, variable statement, expression statement, do-while statement, continue statement, break statement, return statement, and throw statement) must be terminated with semicolons
What are the rules for JavaScript's automatic semicolon insertion (ASI)? 对此也有很好的介绍。
关于java - JSONWithPadding 中缺少分号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16341615/