gpt4 book ai didi

json - JSON Patch RFC 中的波浪号转义应该如何操作?

转载 作者:行者123 更新时间:2023-12-02 09:43:18 46 4
gpt4 key购买 nike

引用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/

46 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com