gpt4 book ai didi

java - 如何在 Java 中从 JSON 字符串中获取数组?

转载 作者:太空宇宙 更新时间:2023-11-04 10:51:33 25 4
gpt4 key购买 nike

我有一个如下的 JSON 字符串,我从 Web 服务调用中获取该字符串。如何从 builds 键检索数组。

 {
"actions" : [
{

},
null,
{

}
],
"description" : "<a href=\"ws/product/target/product-10.7-SNAPSHOT.zip\" style=\"font-size: 50px\">Download Branch Build</a>",
"displayName" : "EPIC-AUTODEV-8413",
"displayNameOrNull" : null,
"name" : "EPIC-AUTODEV-8413",
"url" : "http://localhost:80/jenkins/view/Branch-Builds/job/EPIC-AUTODEV-8413/",
"buildable" : false,
"builds" : [
{
"number" : 71,
"url" : "http://localhost:80/jenkins/view/Branch-Builds/job/EPIC-AUTODEV-8413/71/"
},
{
"number" : 70,
"url" : "http://localhost:80/jenkins/view/Branch-Builds/job/EPIC-AUTODEV-8413/70/"
},
{
"number" : 69,
"url" : "http://localhost:80/jenkins/view/Branch-Builds/job/EPIC-AUTODEV-8413/69/"
},
{
"number" : 68,
"url" : "http://localhost:80/jenkins/view/Branch-Builds/job/EPIC-AUTODEV-8413/68/"
},
{
"number" : 67,
"url" : "http://localhost:80/jenkins/view/Branch-Builds/job/EPIC-AUTODEV-8413/67/"
},
{
"number" : 66,
"url" : "http://localhost:80/jenkins/view/Branch-Builds/job/EPIC-AUTODEV-8413/66/"
},

}

我尝试过 tree=builds[*] ,但它给了我这样的输出

{"builds":[{},{},{},{},{},{},{},{},{},{},{}]}

最佳答案

尝试javascript方法JSON.parse,下面是示例

var obj = JSON.parse('{ "name":"John", "age":30, "city":"New York"}');

上面会给你对象,而不是你想要的部分。

如果您希望将对象转换回 json,请尝试 JSON.stringify()

var myJSON = JSON.stringify(obj);

关于java - 如何在 Java 中从 JSON 字符串中获取数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47789173/

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