json 可以只有键没有值吗?
Can json have only key without value?
Json 格式定义键和值。还有下面的
{
"Kill"
}
它是可接受的 json 格式吗?
不是,在JSON notation中,对象是key/value对的无序集合,key和value都是必须的元素
如果您显示的对象只是 您想要在 JSON 文本中包含的东西,您可以删除对象包装器:
"Kill"
完全正确 JSON。 (曾经有一段时间 JSON 被定义为要求最外层的元素是对象或数组,但很多很多年都不是这样了。)
original JSON introduction 非常straight-forward,包括可能的构造图。其中正文内容是这样的:
An object is an unordered set of name/value pairs. An object begins with {
left brace and ends with }
right brace. Each name is followed by :
colon and the name/value pairs are separated by ,
comma.
后面的ECMA-404 standard包括类似的措辞:
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.
IETF standard, RFC 8259是这样说的:
An object structure is represented as a pair of curly brackets
surrounding zero or more name/value pairs (or members). A name is a
string. A single colon comes after each name, separating the name
from the value. A single comma separates a value from a following
name. The names within an object SHOULD be unique.
在每种情况下,请注意 每个 键后跟一个冒号和一个值。由于您的示例中的键后面没有冒号,因此它无效 JSON.
Json 格式定义键和值。还有下面的
{
"Kill"
}
它是可接受的 json 格式吗?
不是,在JSON notation中,对象是key/value对的无序集合,key和value都是必须的元素
如果您显示的对象只是 您想要在 JSON 文本中包含的东西,您可以删除对象包装器:
"Kill"
完全正确 JSON。 (曾经有一段时间 JSON 被定义为要求最外层的元素是对象或数组,但很多很多年都不是这样了。)
original JSON introduction 非常straight-forward,包括可能的构造图。其中正文内容是这样的:
An object is an unordered set of name/value pairs. An object begins with
{
left brace and ends with}
right brace. Each name is followed by:
colon and the name/value pairs are separated by,
comma.
后面的ECMA-404 standard包括类似的措辞:
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.
IETF standard, RFC 8259是这样说的:
An object structure is represented as a pair of curly brackets surrounding zero or more name/value pairs (or members). A name is a string. A single colon comes after each name, separating the name from the value. A single comma separates a value from a following name. The names within an object SHOULD be unique.
在每种情况下,请注意 每个 键后跟一个冒号和一个值。由于您的示例中的键后面没有冒号,因此它无效 JSON.