读取json数组里面的某个数据

代码
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

import net.sf.json.JSON;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public class Weather {
static JSONObject jsonobject,jsonobject1;
static JSONArray jsonArray;
public static void main(String[] args) throws IOException {
URL u = new URL(“http://www.weather.com.cn/data/sk/101110101.html”);
InputStream in = u.openStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
byte buf[] = new byte[1024];
int read = 0;
while ((read = in .read(buf)) > 0) {
out.write(buf, 0, read);
}
} finally {
if ( in != null) {
in .close();
}
}
byte b[] = out.toByteArray();
String result=new String(b, “utf-8”);
System.out.println(result);
jsonobject = JSONObject.fromObject(result);
System.out.println(jsonobject.getString(“weatherinfo”));
String data=jsonobject.getString(“weatherinfo”);
jsonobject1 = JSONObject.fromObject(data);
System.out.println( jsonobject1.getString(“temp”));
}

}

结果读取json数组里面的某个数据_第1张图片

你可能感兴趣的:(读取json数组里面的某个数据)