这是有效的json吗?
{
"a" : "x",
"a" : "y"
}
http://jsonlint.com/表示同意.
http://www.json.org/ doesn't say anything about it being forbidden.
但很明显这没有多大意义,是吗?
这是有效的json吗?
{
"a" : "x",
"a" : "y"
}
http://jsonlint.com/表示同意.
http://www.json.org/ doesn't say anything about it being forbidden.
但很明显这没有多大意义,是吗?
预计其他标准将引用此标准,严格遵循JSON文本格式,而 对各种编码细节施加限制.这样的标准可能需要特定的行为.JSON 其本身并没有规定任何行为.
Further down in the standard (p. 2), the specification for a JSON object:
An object structure is represented as a pair of curly bracket tokens surrounding zero or more name/value pairs. A name is a string. A single colon token follows each name, separating the name from the value. A single comma token separates a value from a following name.
它没有提到任何重复的键是无效或有效的,所以根据规范,我可以安全地假设这意味着它们是允许的.
That most implementations of JSON libraries do not accept duplicate keys does not conflict with the standard, because of the first quote.
Here are two examples related to the C++ standard library. When deserializing some JSON object into a std::map
it would make sense to refuse duplicate keys. But when deserializing some JSON object into a std::multimap
it would make sense to accept duplicate keys as normal.