gpt4 book ai didi

java - 将 JSON 字符串转换为 Java

转载 作者:行者123 更新时间:2023-12-01 04:21:33 25 4
gpt4 key购买 nike

我正在尝试将 imbdapi 的输出从 JSON 转换。我一直在研究如何做到这一点,但似乎无法弄清楚 GSON。谢谢,抱歉,我自己无法弄清楚,我绝不是想让人觉得我是在要求用勺子喂食。如果有人可以提供一些帮助,我将不胜感激。

public class Test {

public static String getMovieInfo(String movie) {
BufferedReader rd;
OutputStreamWriter wr;
//Scanner s = new Scanner(System.in);
//System.out.println("Enter input:");
//movie = s.nextLine();
//movie = movie.replaceAll(" ", "%20");
if (movie != null)
{
try {
URL url = new URL("http://www.imdbapi.com/?i=&t=" + movie);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
wr = new OutputStreamWriter(conn.getOutputStream());
wr.flush();

// Get the response
rd = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String line = rd.readLine();
if (line != null) {
return line;
} else {

return "Sorry! That's not a valid URL.";
}
} catch (UnknownHostException codeyellow) {
System.err.println("Caught UnknownHostException: " + codeyellow.getMessage());
}
catch (IOException e)
{
System.out.println("Caught IOException:" + e.getMessage());
}

}
else
{
return "passed parameter is null!";
}

return "an error occured, see console!";
}
}

最佳答案

好吧!我自己解决了这个问题,Quick-JSON 的文档有点粗糙,但我解决了。 https://code.google.com/p/quick-json/如果其他人想要它,感谢布兰登向我展示。谢谢!

关于java - 将 JSON 字符串转换为 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18854607/

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