{
key1 : value1,
key2 : value2,
.............
keyT: [
{
key11: value11,
key12: value12,
......
keyA: value1A,
......
keyB: value1B,
.......
keyN: value1N
},
{
key11: value21,
key12: value22,
......
keyA: value2A,
......
keyB: value2B,
.......
keyN: value2N
},
.........
keyM: valueM,
}
keyA:value1A keyB:value1B
keyA:value2A keyB:value2B
..........
keyA:valueKA keyB:valueKB
package testJa;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.Iterator;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
//this class to analysis json via recursion
public class jsonOp {
public void jsonPattern(String inFile,String outFile,String patt) throws IOException, JSONException{
File fi = new File(inFile);
if(fi.isFile() && fi.exists()){
//read file
InputStreamReader in = new InputStreamReader(new FileInputStream(fi));
BufferedReader br = new BufferedReader(in);
String jsonStr = br.readLine(); //read by line
//write file
File fo = new File(outFile);
OutputStream out = new FileOutputStream(fo);
String [] pats = patt.split(":");
String [] pat_detail = pats[1].split(",");
JSONArray ja = getJsonArray(jsonStr,pats[0]); //get target json array
//get target items from json array via pattern
int len = ja.length();
for(int i=0;i
String patt = "seats:seatID,seatName";
String inFile = "/Users/xx/Downloads/tmp/seatidseatname.txt";
String outFile= "/Users/xx/Downloads/tmp/out.txt";
{"code":"0000","message”:”xx”,”data":{"scheduleID”:xx,”cinemaID”:”xx”,”showID”:”xx”,”currentTime”:xx,”hallName":"4","cinemaName”:”xx”,"openTime":"22:45:00","openDate":"2017-09-14","loverSeat":false,"mobile”:”xx”,"regular":false,"seats":[{"status":1,"seatID":"3661","topPx":42,"leftPx":175,"flag":0,"rowName":"A","seatName":"A01","column":0,"row":0},{"status":1,"seatID":"3662","topPx":42,"leftPx":208,"flag":0,"rowName":"A","seatName":"A02","column":0,"row":0},{"status":1,"seatID":"3787","topPx":386,"leftPx":505,"flag":0,"rowName":"L","seatName":"L11","column":0,"row":0},{"status":0,"seatID":"3788","topPx":386,"leftPx":538,"flag":0,"rowName":"L","seatName":"L12","column":0,"row":0}],"soldCount":21,"minTopPx":42,"maxLeftPx":538,"maxTopPx":386,"maxColumn":0,"minColumn":0,"maxRow":0,"minRow":0}}}
JSONArray ja = getJsonArray(value,listKey); //recursion
if(ja!=null){
return ja;
}
如果没有这个条件判断,返回值是有问题的。