一维数据
private static String jsonAnalysis3(String content) {
JSONArray jsonArray;
String aqi = null, area = null, pm25 = null, quality = null, time = null;
String top10 = "";
try{
jsonArray = new JSONArray(content);
top10 += "全国前十排行榜\n\n";
for(int i=0; i< 10; i++) {
JSONObject obj = (JSONObject) jsonArray.get(i);
aqi = obj.getString("aqi");
area = obj.getString("area");
pm25 = obj.getString("pm2_5");
quality = obj.getString("quality");
top10 += (area+"AQI"+aqi+"PM2.5"+pm25+quality+"\n");
time = obj.getString("time_point");
}
top10 += "获取时间"+time;
}catch (Exception e){
e.printStackTrace();
}
return top10;
}
public static String[][] jsonAnalysis(String content) {
JSONArray jsonArray;
try {
jsonArray = new JSONArray(content);
String[][] data = new String[jsonArray.length()][7];
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject obj = jsonArray.getJSONObject(i);
data[i][0] = obj.getString("area");
data[i][1] = obj.getString("time_point");
data[i][2] = obj.getString("aqi");
data[i][3] = obj.getString("pm2_5");
data[i][4] = obj.getString("pm2_5_24h");
data[i][5] = obj.getString("quality");
data[i][6] = obj.getString("position_name");
}
return data;
}catch(Exception e){
e.printStackTrace();
}
return null;
}