I'm trying to represent a collection of objects within a JSON string, and would like to know if the format below is correct:
我试图在JSON字符串中表示对象的集合,并想知道下面的格式是否正确:
"books"
{
"001"
{
"title" "Title 1"
"author" "Author 1"
"dimension"
{
"height" "#cm"
"width" "#cm"
}
}
"002"
{
"title" "Title 2"
"author" "Author 2"
"dimension"
{
"height" "#cm"
"width" "#cm"
}
}
}
Is the string above valid JSON
data? I wanted to represent it like this:
字符串是否在有效的JSON数据之上?我想像这样代表它:
Book Lists
Book Title | Book Author | Book Dimension | Book ID
Title 1 | Author 1 | Height:#cm;Width#cm | 001
Title 2 | Author 2 | Height:#cm;Width#cm | 002
1 个解决方案
#1
As mentioned, your format is not valid JSON.
如上所述,您的格式无效JSON。
To represent your JSON as you would like, it would need to be in the following format:
要根据需要表示您的JSON,它需要采用以下格式:
{
"books": [
{
"id": "001",
"title": "Title 1",
"author": "Author 1",
"dimension": {
"height": "#cm",
"width": "#cm"
}
},
{
"id": "002",
"title": "Title 2",
"author": "Author 2",
"dimension": {
"height": "#cm",
"width": "#cm"
}
}
]
}
You can use an online JSON parser to help determine if your JSON data is valid or not: http://json.parser.online.fr/
您可以使用在线JSON解析器来帮助确定您的JSON数据是否有效:http://json.parser.online.fr/
#1
As mentioned, your format is not valid JSON.
如上所述,您的格式无效JSON。
To represent your JSON as you would like, it would need to be in the following format:
要根据需要表示您的JSON,它需要采用以下格式:
{
"books": [
{
"id": "001",
"title": "Title 1",
"author": "Author 1",
"dimension": {
"height": "#cm",
"width": "#cm"
}
},
{
"id": "002",
"title": "Title 2",
"author": "Author 2",
"dimension": {
"height": "#cm",
"width": "#cm"
}
}
]
}
You can use an online JSON parser to help determine if your JSON data is valid or not: http://json.parser.online.fr/
您可以使用在线JSON解析器来帮助确定您的JSON数据是否有效:http://json.parser.online.fr/