标签/值的 JSON 列表

发布于 2024-09-25 02:43:47 字数 581 浏览 1 评论 0原文

我正在开发一个需要一个对象具有多个值的项目。例如,“事物”列表都有一个名称,但每个事物也有另一个类别,“标签”可能包括圆形、圆圈、球、运动等事物。所有描述“事物”是什么的单词。我试图在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

捂风挽笑 2024-10-02 02:43:47

你的“标签”对象对我来说似乎很奇怪。代码:

[{"globe","circle","round","world"}]

将尝试创建一个对象的数组,该对象的属性没有任何值,但我不确定这是否是有效的语法。您想要“标签”的单词数组吗?如果是这样,您需要删除那些花括号:

var myThings = {
    "things":[{
        "name":"thing1",
        "tags":["globe","circle","round","world"]
    }]
};

这将为您提供一个具有属性“things”的对象,其中包含一个具有“name”和“tags”属性的对象的数组,其中“tags”是一组单词。

您可以像这样访问“标签”:

var thing1tag2 = myThings.things[0].tags[1]; // = "circle"

Your "tags" objects seem off to me. The code:

[{"globe","circle","round","world"}]

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:

var myThings = {
    "things":[{
        "name":"thing1",
        "tags":["globe","circle","round","world"]
    }]
};

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:

var thing1tag2 = myThings.things[0].tags[1]; // = "circle"
誰認得朕 2024-10-02 02:43:47

如果每个事物都有一个名称,那么为什么不使用该名称作为标签,如下所示:

var things = {
  "thing1": ["globe", "circle", "round", "world"],
  "thing2": ["cloud", "weather", "lightning", "sky"],
  "thing3": ["round", "bullseye", "target"],
  "thing4": ["round", "key", "lock"],
  "thing5", ["weather", "sun", "sky", "summer"]
};

现在您可以引用 things.thing1things.thing2 以及标签作为 things.thing1[0]things.thing2[2] 等。

If each thing has a name then why not use that name as a tag as follows:

var things = {
  "thing1": ["globe", "circle", "round", "world"],
  "thing2": ["cloud", "weather", "lightning", "sky"],
  "thing3": ["round", "bullseye", "target"],
  "thing4": ["round", "key", "lock"],
  "thing5", ["weather", "sun", "sky", "summer"]
};

Now you can refer to things.thing1 or things.thing2 and the tags as things.thing1[0] and things.thing2[2] etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文