[英]Convert JSON string to Java
我正在嘗試從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/(如果有人需要),感謝Brandon給我看。 謝謝!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.