gpt4 book ai didi

java - 为 optJSONArray 取空

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

所以我有这条线:

JSONObject res = new JSONObject(result);

这个的输出是:

{
"result": "[\"Pretty Woman\",\"Minions Banana Song\",\"Squatters Rights\",\"Minions Banana\",\"Minions Puppy\"]",
"id": 0,
"jsonrpc": "2.0"
}

然后我有一行:

JSONArray moviesJson = res.optJSONArray("result");

并且其输出为空。这是我的语法错误吗?我不知道发生了什么。

我试图将结果中包含的数组作为我的输出

最佳答案

result 包含一个数组,但以单个字符串的形式。您可以获得数组:

JSONArray moviesJson = new JSONArray(res.getString("result"));

关于java - 为 optJSONArray 取空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46538507/

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