JSON Pointer规范说明:
the characters '~' (%x7E) and '/' (%x2F) have special meanings in JSON Pointer
很清楚 '/' 的用途是什么,但我看不到波浪号有什么用途的迹象(只提到它需要转义以及如何转义)。
最佳答案
在 JSON 指针中,您需要使用 ~1
编码你想要的 /
作为路径中属性名称的一部分。正因为如此,~
获得特殊含义作为转义序列的指示符,不再表示真正的波浪号。真正的波浪号表示为转义序列 ~0
.
换句话说(引用自 JSON Pointer 规范):
Evaluation of each reference token begins by decoding any escaped character sequence. This is performed by first transforming any occurrence of the sequence '~1' to '/', and then transforming any occurrence of the sequence '~0' to '~'. By performing the substitutions in this order, an implementation avoids the error of turning '~01' first into '~1' and then into '/', which would be incorrect (the string '~01' correctly becomes '~1' after transformation).
在此处查看 JSON 补丁测试可能会很有趣:https://github.com/json-patch/json-patch-tests/blob/master/spec_tests.json#L200 (搜索
~
)
关于json - JSON 指针中波浪号的用途,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31483170/