读取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”));
}
}
结果
AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐



所有评论(0)