0

我想知道如果 JSON Lines 文件的结构如下:

{"structure1":"some kind of file header"}
{"structure2": [ {"key1":"aaa", "key2":"bbb"}, {"key1":"one", "key2":"two"}]
{"structure2": [ {"key1":"xxx", "key2":"yyy"}, {"key1":"first", "key2":"second"}]
{"structure3":"maybe some kind of file footer"}

它是否被视为无效的 JSONLines 格式?我查看了http://jsonlines.org/上的标准,但我看不到任何一种方式。谢谢你。

4

1 回答 1

0

您的每一行都是有效的(但缺少“}”以及第二和第三行的结尾)。但是如果你想把它们全部放在一个文件中,那将是无效的。它们必须在数组中并,用键/值或对象分隔(其中值可以是数组或对象)

数组示例:

[
 {"structure1":"some kind of file header"},
 {"structure2": [ {"key1":"aaa", "key2":"bbb"}, {"key1":"one", "key2":"two"}]},
 {"structure2": [ {"key1":"xxx", "key2":"yyy"}, {"key1":"first", "key2":"second"}]},
 {"structure3":"maybe some kind of file footer"}
]

或一个对象:

{
"structure1": "some kind of file header",
"structure2": [{
    "key1": "aaa",
    "key2": "bbb"
}, {
    "key1": "one",
    "key2": "two"
}],
"structure2": [{
    "key1": "xxx",
    "key2": "yyy"
}, {
    "key1": "first",
    "key2": "second"
}],
"structure3": "maybe some kind of file footer"

}

您可以在此站点上测试您的 json 以查看是否有效:http: //www.jslint.com/http://jsonlint.com/

于 2016-04-07T21:19:22.980 回答