如何将json格式的string字符串转换为string数组

public static void main(String[] args){
String s="[{\"type\":\"城际高速\",\"station\":\"北京南\",\"stationNO\":\"1\",\"days\":\"1\",\"arriveTime\":\"-\",\"startDriveTime\":\"08:45\",\"km\":\"0\"},{\"type\":\"城际高速\",\"station\":\"天津\",\"stationNO\":\"2\",\"days\":\"1\",\"arriveTime\":\"09:15\",\"startDriveTime\":\"-\",\"km\":\"120\"}]";
Object obj=JSONValue.parse(s);
JSONArray array=(JSONArray)obj;
Iterator iter = array.iterator();
String[][] ary = new String[array.size()+1][7];
String[] ss = {"type", "station","stationNO", "days", "arriveTime", "startDriveTime", "km"};
int[] a = {1,2,3};
ary[0] = ss;
int i=1;
while(iter.hasNext()){
JSONObject jObj = (JSONObject)iter.next();
ary[i] = new String[7];
ary[i][0] = (String)jObj.get("type");
ary[i][1] = (String)jObj.get("station");
ary[i][2] = (String)jObj.get("stationNO");
ary[i][3] = (String)jObj.get("days");
ary[i][4] = (String)jObj.get("arriveTime");
ary[i][5] = (String)jObj.get("startDriveTime");
ary[i][6] = (String)jObj.get("km");
i++;
}
System.out.println(Arrays.toString(ary[0]));
System.out.println(Arrays.toString(ary[1]));
System.out.println(Arrays.toString(ary[2]));
}

你可能感兴趣的:(类型转换)