//Open url and fetch JSON data
String s = "MY_URL_HERE";
URL url = new URL(s);
Scanner scan = new Scanner(url.openStream());
String str = new String();
while (scan.hasNext())
{
str += scan.nextLine();
}
scan.close();
System.out.println(str);
海峽將打印像一個字符串:如何從JSON字符串一個特定的值
{"coord":{"lon":-80.25,"lat":43.55},"weather":[{"id":800,"main":"Clear","description":"Sky is Clear","icon"...ect
我使用json_simple-1.1.jar
如何實際使用此字符串來提取我選擇的價值?如果我想拉出「描述」或「天氣」。
我曾嘗試與代碼片斷:
https://code.google.com/p/json-simple/wiki/DecodingExamples
這些不爲我工作,我得到一個錯誤
org.json.simple.JSONObject cannot be cast to org.json.simple.JSONArray
不錯,我也記得。 – Acewin
也可以請添加,如果它是一個對象列表將會發生 – Acewin
JSONObject.get(「coord」)我不確定你是什麼意思。 我應該先創建一個對象 JSONObject obj = new JSONObject(); ?? –