gpt4 book ai didi

json - 如何使用 groovy 解析 json

转载 作者:IT老高 更新时间:2023-10-28 12:46:32 26 4
gpt4 key购买 nike

我想解析像这样进来的 JSON 数据:

{
"212315952136472": {
"id": "212315952136472",
"name": "Ready",
"picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/195762_212315952136472_4343686_s.jpg",
"link": "http://www.hityashit.com/movie/ready",
"likes": 5,
"category": "Movie",
"description": "Check out the reviews of Ready on http://www.hityashit.com/movie/ready"
}
}

我使用的代码是:

JSONElement userJson = JSON.parse(jsonResponse)
userJson.data.each {
Urls = it.link
}

但我无法获得分配给 Urls 的任何内容。有什么建议吗?

最佳答案

您是否尝试过使用 JsonSlurper ?

示例用法:

def slurper = new JsonSlurper()
def result = slurper.parseText('{"person":{"name":"Guillaume","age":33,"pets":["dog","cat"]}}')

assert result.person.name == "Guillaume"
assert result.person.age == 33
assert result.person.pets.size() == 2
assert result.person.pets[0] == "dog"
assert result.person.pets[1] == "cat"

关于json - 如何使用 groovy 解析 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6688090/

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