gpt4 book ai didi

java - Spring RestTemplate 解析具有可变键名的 JSON 对象

转载 作者:行者123 更新时间:2023-11-30 10:29:40 26 4
gpt4 key购买 nike

我有一个返回以下 JSON 对象的 REST API 调用。我需要用 Spring 的 RestTemplate 来解析它。问题是第一个键 ISBN:0132856204 是可变的(数字根据书籍而变化)。我该怎么做呢?

{
"ISBN:0132856204": {
"publishers": [
{
"name": "Pearson"
}
],
"pagination": "xxiv, 862p",
"identifiers": {
"isbn_13": [
"978-0-13-285620-1"
],
"openlibrary": [
"OL25617855M"
]
},
"weight": "1340 grams",
"title": "Computer networking",
"url": "https://openlibrary.org/books/OL25617855M/Computer_networking",
"number_of_pages": 862,
"cover": {
"small": "https://covers.openlibrary.org/b/id/7290810-S.jpg",
"large": "https://covers.openlibrary.org/b/id/7290810-L.jpg",
"medium": "https://covers.openlibrary.org/b/id/7290810-M.jpg"
},
"publish_date": "2013",
"key": "/books/OL25617855M",
"authors": [
{
"url": "https://openlibrary.org/authors/OL31244A/James_F._Kurose",
"name": "James F. Kurose"
},
{
"url": "https://openlibrary.org/authors/OL658909A/Keith_W._Ross",
"name": "Keith W. Ross"
}
],
"subtitle": "A Top-Down Approach"
}
}

最佳答案

在这里“ISBN:0132856204”是一个值(value),也是您业务的关键。要首先获得 ISBN,用 1 个闭包包装 json 内容怎么样?

{
"yourAwesomePlaceHolderKey" :
{
"ISBN:0132856204": {
......
}
}
}

首先获取 ISBN 键作为值,然后您的 ISBN 值可以作为获取相关内容的键。

第一个目标是提取 -String1,Object1- 对,其中 String1 是“yourAwesomePlaceholderKey”,第二个目标将再次从 Object1 中提取 -String2,Object2-,其中 String2 是您的 ISBN 键。

关于java - Spring RestTemplate 解析具有可变键名的 JSON 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43939689/

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