I'm trying to represent a collection of objects within a JSON string, and would like to know if the format below is correct:
<div ng-controller="myController">
<div some-directive ng-model="some-directive-scope.variable>
{{ some-directive-scope.variable }}
</div>
<p ng-bind="some-directive-scope.variable"></p>
</div>
Is the string above valid "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"
}
}
}
data? I wanted to represent it like this:
JSON
答案 0 :(得分:1)
如上所述,您的格式无效JSON。
要根据需要表示您的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"
}
}
]
}
您可以使用在线JSON解析器来帮助确定您的JSON数据是否有效:http://json.parser.online.fr/