这只是我需要访问的一段 JSON 代码......
"forecast":{
"txt_forecast": {
"date":"8:00 AM MST",
"forecastday": [
{
"period":0,
"icon":"partlycloudy",
"icon_url":"http://icons-ak.wxug.com/i/c/k/partlycloudy.gif",
"title":"Thursday",
"fcttext":"Partly cloudy. High of 63F. Winds less than 5 mph.",
"fcttext_metric":"Partly cloudy. High of 17C. Winds less than 5 km/h.",
"pop":"0"
}
我无法打印嵌套的 JSON 值。如果我想打印“fcttext”,我会怎么做呢?我试过这个...
public static void display() {
JSONParser parser = new JSONParser();
try {
Object obj = parser.parse(new FileReader("C:\\ABC.json"));
JSONObject jsonObject = (JSONObject) obj;
String a = (String) jsonObject.get("forecast").toString();
System.out.println(a);
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
catch (ParseException e) {
e.printStackTrace();
}
}
我究竟做错了什么?完整的 JSON 代码。