gpt4 book ai didi

android - 如何使用 Retrofit 2.0 解析带有动态键的 json?

转载 作者:行者123 更新时间:2023-11-29 15:37:02 25 4
gpt4 key购买 nike

这是 JSON,其中 jsonObject 键是动态的:

{
"CH000032": [
{
"type": "event",
"details": {
"programID": "MV10000032",
"programType": "MOVIE",
"title": "Titanic",
"year": "1997",
"rating": "PG-13",
"durationSec": 11640,
"startTimeSec": "",
"endTimeSec": "",
"language": "ENG",
"isHD": true,
"Genres": [
"Movies",
"Action"
],
"description": "A seventeen-year-old aristocrat falls in love with a kind but poor artist aboard the luxurious, ill-fated R.M.S. Titanic.",
"imageUrl": "http://res.cloudinary.com/dte07foms/image/upload/c_scale,h_405,w_270/l_Copyright_e3jt1k/v1508831090/Titanic_b0hqo0.jpg"
}
}
],
"CH000033": [
{
"type": "event",
"details": {
"programID": "EP10000132",
"programType": "EPISODE",
"title": "A Chic Bar in Ibiza",
"seriesTitle": "Two and a Half Men",
"seasonNumber": 12,
"epsiodeNumber": 2,
"year": "2014",
"rating": "TV-14",
"durationSec": 1260,
"startTimeSec": "",
"endTimeSec": "",
"language": "ENG",
"isHD": true,
"Genres": [
"Comedy",
"Romance"
],
"description": "Alan has second thoughts about getting married when Walden has him sign a prenup.",
"imageUrl": "http://res.cloudinary.com/dte07foms/image/upload/c_crop,h_405,w_270//l_Copyright_e3jt1k/v1508831090/2AndHalfmen_splkro.jpg"
}
}
]
}

我想解析这个 JSON。请让我知道该怎样上课
使用 Retrofit@SerializedName 注释编写。

注意:CH000032、CH000033 等是动态的。

最佳答案

您可以使用 Map<String, ModelClassName>在您的动态模型类中,如下所示:-

public class Data {
@SerializedName("your_key")
@Expose
private Map<String, ModelClassName> result;

//....
}

这有助于在改造中解析动态 key 。

关于android - 如何使用 Retrofit 2.0 解析带有动态键的 json?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47748006/

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