引用https://www.rfc-editor.org/rfc/rfc6902#appendix-A.14 :
A.14. ~ Escape Ordering
An example target JSON document:
{ "/": 9, "~1": 10 }
A JSON Patch document:
[ {"op": "test", "path": "/~01", "value": 10} ]
The resulting JSON document:
{ "/": 9, "~1": 10 }
我正在编写此 RFC 的实现,但我陷入了困境。这是要实现什么目标,它应该如何工作?
假设第一部分的答案是“允许引用包含/s 的 json 键名称”,您会怎么做?
最佳答案
~
字符是JSON指针中的关键字。因此,我们需要将其“编码”为~0
。引用jsonpatch.com ,
If you need to refer to a key with ~ or / in its name, you must escape the characters with ~0 and ~1 respectively. For example, to get "baz" from { "foo/bar~": "baz" } you’d use the pointer /foo~1bar~0
本质上,
[
{"op": "test", "path": "/~01", "value": 10}
]
解码后的结果
[
{"op": "test", "path": "/~1", "value": 10}
]
关于json - JSON Patch RFC 中的波浪号转义应该如何操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24419391/