-1
我能夠提取名稱值(Nungam Hwy),但我無法單獨獲取時間值(5:30 AM)。如何使用org.json.simple.parser.JSONParser獲取關鍵值對值?
我的代碼:
以下是我的JSON這是我從我的文件中讀取。
private void convertJsonToSql() {
JSONParser parser = new JSONParser();
List<Time> times = new ArrayList<>();
try {
Object obj = parser.parse(new FileReader("/home/bus/route125SaturdaySouthbound"));
JSONArray jsonArray = (JSONArray) obj;
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObj = (JSONObject) jsonArray.get(i);
String stopName = (String) jsonObj.get("Name");
times = (List) jsonObj.get("Times");
System.out.println("Stop name " + stopName);
for (int j = 0; j < times.size(); j++) {
System.out.println("Time" + times.get(j));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
[
{
"StopId":0,
"Name":"Nungam Hwy",
"Times":[
{
"Time":" 5:30AM",
"RouteNumber":"12"
},
{
"Time":" 6:16AM",
"RouteNumber":"12"
}
}
]
請幫助我的人......