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... ----------------------------