无法获取具有重复名称的嵌套 JSON 对象

发布于 2025-01-08 07:58:35 字数 1070 浏览 0 评论 0原文

我对 JSON 很陌生,所以以下可能是一个微不足道的问题,但我在 stackoverflow 上找不到任何类似的问题,所以:

我想获得一个嵌套的 JSON 对象,例如:pizza.topping. rating 但在访问它时说未定义,尽管可以看到评级对象...访问 Pizza.Rating 时它工作正常...这是否与对象 Pizza 中多次使用的“评级”有关?

这种情况有解决方法吗?

非常感谢您的帮助

ps:该对象看起来像这样:

jQuery16207381055671721697_1329849155553(
    {"pizza":
        {"Hjid":2030,
         "creator":"n0rritt",
         "pizzaTitle":"Fungi",
         "rating":
            [
                {"Hjid":2032,
                 "creator":"n0rritt",
                 "ratingText":"it's delicious"}
            ],
         "topping":
            [
                {"Hjid":2031,
                 "creator":"n0rritt",
                 "toppingText":"with fish",
                 "rating":
                     [
                         {"Hjid":2042,
                          "creator":"n0rritt",
                          "creationTime":"2012-02-21T19:08:22.896",
                          "ratingText":"good for your health"}
                     ]
                }
            ]
        }
    }
)

I'm quite new to JSON so the following might be a trivial problem, but I could not find any comparable question on stackoverflow, so:

I would like to get a nested JSON object like: pizza.topping.rating but when accessing it says undefined, although can see the rating object ... when accessing pizza.rating it works fine ... does it have something to do with the "rating" being used within the object pizza several times?

is there a work around for this situation?

thank you very much for your help

ps: the object looks something like this:

jQuery16207381055671721697_1329849155553(
    {"pizza":
        {"Hjid":2030,
         "creator":"n0rritt",
         "pizzaTitle":"Fungi",
         "rating":
            [
                {"Hjid":2032,
                 "creator":"n0rritt",
                 "ratingText":"it's delicious"}
            ],
         "topping":
            [
                {"Hjid":2031,
                 "creator":"n0rritt",
                 "toppingText":"with fish",
                 "rating":
                     [
                         {"Hjid":2042,
                          "creator":"n0rritt",
                          "creationTime":"2012-02-21T19:08:22.896",
                          "ratingText":"good for your health"}
                     ]
                }
            ]
        }
    }
)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

猫七 2025-01-15 07:58:35

pizza.topping 是一个数组。因此,您必须访问数组索引。就像这样:pizza.topping[0]. rating

那里的其余数组也是如此。

pizza.topping is an array. Therefore you must access an array index. Like so: pizza.topping[0].rating.

The same goes for the rest of your arrays in there.

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