gpt4 book ai didi

java - JSON解析-获取值

转载 作者:行者123 更新时间:2023-12-01 18:48:28 24 4
gpt4 key购买 nike

我在解析此 JSON 时遇到问题。我在 JSONObject o 中有以下数据。我如何获取critics_score的值?

{
"total":1,"
movies":
[{
"id":"770672122",
"title":"Toy Story 3",
"year":2010,
"mpaa_rating":"G",
"runtime":103,
"critics_consensus":"Deftly blending comedy, adventure, and honest emotion, Toy Story 3 is a rare second sequel that really works.",

"release_dates":{"theater":"2010-06-18","dvd":"2010-11-02"},
"ratings":
{
"critics_rating":"Certified Fresh",
"critics_score":99,
"audience_rating":"Upright", .......

谢谢

最佳答案

您可以执行以下操作:

    int criticsScore;
try {
criticsScore = myJsonObject.getJSONArray("movies").getJSONObject(0).getJSONObject("ratings").getInt("critics_score");
} catch (JSONException e) {
e.printStackTrace();
}

编辑:假设您的 JSONObject 名为 myJsonObject

关于java - JSON解析-获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16660034/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com