gpt4 book ai didi

java - 如何访问 key "text/plain"中的数据

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

这是我得到的 json

{
"id": 21,
"code": "import scala.collection.JavaConversions._;import java.io.File;def getFileTree(f: File): Stream[File] =f #:: (if (f.isDirectory){ f.listFiles().toStream} else{ Stream.empty});getFileTree(new File(\"/home/datagaps/Downloads/\")).filter(_.getName.endsWith(\".json\")).foreach(println);",
"state": "available",
"output": {
"status": "ok",
"execution_count": 21,
"data": {
"text/plain": "/home/datagaps/Downloads/santanu.json\nimport scala.collection.JavaConversions._\nimport java.io.File\ngetFileTree: (f: java.io.File)Stream[java.io.File]\n"
}
},
"progress": 1
}

这是我编写的用于访问字符串的代码。

String output=getGETRequestResponse(uri).getJSONObject("output").getJSONObject("data").getString("text/plain");

org.json.JSONException: JSONObject["output"] is not a JSONObject.
at org.json.JSONObject.getJSONObject(JSONObject.java:736)
at com.datagaps.livyservice.service.LivyServerServiceImpl.getFilePaths(LivyServerServiceImpl.java:229)
at com.datagaps.LivyProject.LivyServiceApplication.main(LivyServiceApplication.java:53)

运行代码时出现以下异常。

最佳答案

你可以尝试这样的事情:

String output=getGETRequestResponse(uri).getJSONObject("output").getJSONObject("data").toString();
ObjectMapper mapper = new ObjectMapper();
Map<String, String> map = mapper.readValue(output, Map.class);
System.out.ptintln(map.get("text/plain"));

如果你得到了什么,请告诉我。

关于java - 如何访问 key "text/plain"中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55969154/

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