且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JSON 键是否需要唯一?

更新时间:2023-11-30 14:59:58

使用多个同名键不会出现错误",但在 JSON 中,最后一个同名键是将被使用.

There is no "error" if you use more than one key with the same name, but in JSON, the last key with the same name is the one that is going to be used.

在您的情况下,键名称"***包含一个数组作为其值,而不是包含多个键名称".同一个对象或事物"有两个名称,或者两个相同的属性发生冲突,这没有多大意义.

In your case, the key "name" would be better to contain an array as it's value, instead of having a number of keys "name". It doesn't make much sense the same object or "thing" to have two names, or two of the same properties that are in conflict.

例如:

{
  "name" : [ "JOHN", "JACK", "...", ... ]
}