gpt4 book ai didi

java - java解析JSON时出错

转载 作者:行者123 更新时间:2023-12-02 11:16:48 26 4
gpt4 key购买 nike

我收到来自 API 的响应,该响应生成带有其他一些属性的授权 token ,我正在尝试从响应中提取 token 的值,如下所示

 {"access_token":"tokenvalue","scope":"somevalue","token_type":"Bearer","expires_in":value}

我尝试了如下 JSON 解析:

 Myclass response = template.postForObject(url, requestEntity,  Myclas.class);
JSONParser jsonParser = new JSONParser();
JSONObject obj = (JSONObject) jsonParser.parse(response);
String product = (String) jsonObject.get("access_token");
token = response;
}

收到错误:

parse( ) 
in JSONParser cannot be applied
to
(java.lang.String)

最佳答案

用行:

String product = (String) jsonObject.get("access_token");

您正在尝试获取名为“access_token”的属性。

但是,如果您查看 json,您会发现没有名为“access_token”的属性。

也许你的意思是:

String product = (String) jsonObject.get("token");

关于java - java解析JSON时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50216707/

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