我想存儲鍵值項的數組,做一個共同的方式,這可能是這樣的:存儲密鑰值數組成一個緊湊的JSON字符串
// the JSON data may store several data types, not just key value lists,
// but, must be able to identify some data as a key value list
// --> more "common" way to store a key value array
{
[
{"key": "slide0001.html", "value": "Looking Ahead"},
{"key": "slide0008.html", "value": "Forecast"},
{"key": "slide0021.html", "value": "Summary"},
// another THOUSANDS KEY VALUE PAIRS
// ...
],
"otherdata" : { "one": "1", "two": "2", "three": "3" }
}
但是,當有許多對/的物品,該字符串長度變禁止, 和我希望有一個緊湊的方式,這可能是一個例子:
// --> (1) a "compact" way to store a key value array
{
[
{"slide0001.html", "Looking Ahead"},
{"slide0008.html", "Forecast"},
{"slide0021.html", "Summary"},
// another THOUSANDS KEY VALUE PAIRS
// ...
],
"otherdata" : { "one": "1", "two": "2", "three": "3" }
}
此外,我想辦法來識別數據爲密鑰值陣列, 因爲,我可能要將其他數據存儲在同一個JSON文件中。 我有這方面的例子:
// --> (2) a "compact" way to store a key value array
{
"keyvaluelist":
[
{"slide0001.html", "Looking Ahead"},
{"slide0008.html", "Forecast"},
{"slide0021.html", "Summary"},
// another THOUSANDS KEY VALUE PAIRS
// ...
],
"otherdata" : { "one": "1", "two": "2", "three": "3" }
}
// --> (3) a "compact" way to store a key value array
{
"mylist":
{
"type": "keyvaluearray",
"data":
[
{"slide0001.html", "Looking Ahead"},
{"slide0008.html", "Forecast"},
{"slide0021.html", "Summary"},
// another THOUSANDS KEY VALUE PAIRS
// ...
]
},
"otherdata" : { "one": "1", "two": "2", "three": "3" }
}
你有什麼建議,你有你的東西,其中之一另一種方式? 謝謝。
更新1:刪除無效的代碼。的Javascript => JSON
UPDATE 2:添加非關鍵值數據
UPDATE 3:替換 「[」 和 「]」 爲 「{」 和 「}」 中的每個密鑰值對
代碼中沒有一行JSON。只有JavaScript對象。 –
@Felix Kling。謝謝。我刪除使它成爲無效的代碼,如JS而不是JSon – umlcat
它仍然不是JSON。在JSON中,每個鍵(和字符串)都必須用雙引號引起來,而'param ='不存在。 –