标签/值的 JSON 列表
我正在开发一个需要一个对象具有多个值的项目。例如,“事物”列表都有一个名称,但每个事物也有另一个类别,“标签”可能包括圆形、圆圈、球、运动等事物。所有描述“事物”是什么的单词。我试图在 JSON 中定义它,但我总是遇到 jsonlint 错误。看一下:
{
"things":[{
"name":"thing1",
"tags":[{"globe","circle","round","world"}]
},
{
"name":"thing2",
"tags":[{"cloud","weather","lightning","sky"}]
},
{
"name":"thing3",
"tags":[{"round","bullseye","target"}]
},
{
"name":"thing4",
"tags":[{"round","key","lock"}]
},
{
"name":"thing5",
"tags":[{"weather","sun","sky","summer"}]
}]
}
希望您能看到我正在努力实现的目标。
感谢您的帮助!
安东尼
I am working on a project that requires an object to have multiple values. For instance, a list of 'things' all with a name but each thing also has another category, "Tags" with could include things like round, circle, ball, sport, etc. all words describing what the 'thing' is. I am trying to define this in JSON but I keep running into errors with jsonlint. Take a look:
{
"things":[{
"name":"thing1",
"tags":[{"globe","circle","round","world"}]
},
{
"name":"thing2",
"tags":[{"cloud","weather","lightning","sky"}]
},
{
"name":"thing3",
"tags":[{"round","bullseye","target"}]
},
{
"name":"thing4",
"tags":[{"round","key","lock"}]
},
{
"name":"thing5",
"tags":[{"weather","sun","sky","summer"}]
}]
}
Hopefully you see what I am trying to accomplish.
Thanks for your help!
Anthony
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的“标签”对象对我来说似乎很奇怪。代码:
将尝试创建一个对象的数组,该对象的属性没有任何值,但我不确定这是否是有效的语法。您想要“标签”的单词数组吗?如果是这样,您需要删除那些花括号:
这将为您提供一个具有属性“things”的对象,其中包含一个具有“name”和“tags”属性的对象的数组,其中“tags”是一组单词。
您可以像这样访问“标签”:
Your "tags" objects seem off to me. The code:
would try to create an array of an object whose properties don't have any values, but I'm not sure that's even valid syntax. Do you want an array of words for "tags?" If so, you need to drop those curly braces:
That would give you an object with property "things" that contains an array of one object with a "name" and a "tags" property, where "tags" is an array of words.
You could access "tags" like so:
如果每个事物都有一个名称,那么为什么不使用该名称作为标签,如下所示:
现在您可以引用
things.thing1
或things.thing2
以及标签作为things.thing1[0]
和things.thing2[2]
等。If each thing has a name then why not use that name as a tag as follows:
Now you can refer to
things.thing1
orthings.thing2
and the tags asthings.thing1[0]
andthings.thing2[2]
etc.