如何用JSON中的空元素表示数组? [英] How to represent an array with empty elements in JSON?
本文介绍了如何用JSON中的空元素表示数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在JavaScript中有一个看起来像这样的数组:
I have an array in JavaScript that looks like this:
var pattern = [ ["C5", 3], , , , , , , , ["C5", 3], , , ]
我想将其存储在这样的json文件中:
I want to store it in a json file like this:
{
"pattern": [
["C5", 3], , , , , , , , ["C5", 3], , ,
]
}
JSONLint告诉我这一点:
JSONLint tells me this:
Parse error on line 6:
... ], , ,
---------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['
所以我知道我不能让逗号之间的空格为空.类似于空,但被JSON标准接受了吗?
So I understand I can't let the space between commas empty. What's similar to empty, but is accepted by JSON standards?
此模式文件是我正在制作的Javascript音乐跟踪器的一部分,与脉冲跟踪器相似,我希望json文件尽可能整洁.
This pattern file is part of a Javascript Music Tracker I'm making that's similar to impulse tracker, and I want the json file to be as clean as possible.
推荐答案
如果要在JSON中保留空白,则应使用null
填充它.
If you want to have empty space in JSON, you should fill it with null
.
示例:
var pattern = [ ["C5", 3], null, null, null, null, null, null, null, ["C5", 3], null, null, null, null, ...... ]
这篇关于如何用JSON中的空元素表示数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文