public class testTicketOID {
public static void main(String[] args) throws IOException {
String jsonStr = "";
try {
File file = new File("/Users/jinyan/IdeaProjects/88bugs_service/src/main/java/testPXQ/SessionVO.json");
FileReader fileReader = new FileReader(file);
Reader reader = new InputStreamReader(new FileInputStream(file), "Utf-8");
int ch = 0;
StringBuffer sb = new StringBuffer();
while ((ch = reader.read()) != -1) {
sb.append((char) ch);
}
fileReader.close();
reader.close();
jsonStr = sb.toString();
String SessionVOs = jsonStr;
JSONArray dataListArray = new JSONArray(SessionVOs);
String SessionOID="";
String price="";
String seatPlanOID="";
String ticketOID="";
for (int i = 0; i < dataListArray.length(); i++) {
JSONObject aaa = new JSONObject(dataListArray.get(i).toString());
String showStatus = aaa.get("available").toString();
if (showStatus.equals("true")) {
JSONArray seatplans = new JSONArray(aaa.get("seatplans").toString());
for(int j=0;j<seatplans.length();j++){
JSONObject seatplan = new JSONObject(seatplans.get(j).toString());
String seatPlanAvaliable = seatplan.get("available").toString();
if(seatPlanAvaliable.equals("true")){
SessionOID = seatplan.get("showSessionOID").toString();
JSONArray tickets = new JSONArray(seatplan.get("tickets").toString());
JSONObject ticketList = new JSONObject(tickets.get(0).toString());
price=ticketList.get("price").toString();
seatPlanOID=ticketList.get("seatPlanOID").toString();
ticketOID=ticketList.get("ticketOID").toString();
System.out.println(price);
System.out.println(ticketOID);
System.out.println(j);
System.out.println(tickets);
break;
}
}
break;
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
Java读取json文件并进行处理
转载
------------------------- A little Progress a day makes you a big success... ----------------------------
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
上一篇:Supervisor使用详解
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
读取csv文件进行处理
读取excel 文件根据文件进行操作将操作的结果写入到import csvwith open(r"C:\Users\yantingrui\Desktop\Untitled Folder\1
python excel 爬虫 编码问题 读取excel