我有一个客户使用 JSON 来表示对象。例如:
var person = {
fname: "John",
lname: "Doe",
nicknames: ["jake", "kevin"]
}
出于编辑这些条目的目的,我们希望为每个对象包括 GUIDS。尚未建立嵌入 GUID 的方法。我目前正在考虑做这样的事情:
var person = {
_guids: {
fname: "XXX",
lname: "XXX",
_nicknames: "XXX", /* This GUID corresponds to the nickname container */
nicknames: ["jake-guid", "kevin-guid"],
}
fname: "John",
lname: "Doe",
nicknames: ["jake", "kevin"]
}
如果每个项目都是它自己的对象,它会变得非常混乱,并且在不需要 GUID 的情况下会禁止干净的交换。然而,这种方法也导致了如何处理这样的事情的问题:
var person = {
_guids: {
fname: "XXX",
lname: "XXX",
sacks_of_marbles: ["container-guid",
"first-sacks-guid", ["XXX", "XXX"],
"second-sacks-guid", ["XXX", "XXX"]]
}
fname: "John",
lname: "Doe",
sacks_of_marbles: [["red", "blue-with-swirls"], ["green", "pink"]]
}
关于如何保持清洁、不冗长以及包含 GUID 的能力的任何建议?