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
有什么想法吗?
答案 0 :(得分:1)
分号不会丢失,在大多数情况下(本例和)中都是可选。所以JSONWithPadding
类正常工作。
ECMAScript语言规范定义了7.9.1 Rules of Automatic Semicolon Insertion,从JavaScript and Semicolons汇总为
某些ECMAScript语句(空语句,变量语句,表达式语句,do-while语句,continue语句,break语句,return语句和throw语句)必须以分号结束
What are the rules for JavaScript's automatic semicolon insertion (ASI)?
也涵盖了这一点