通过一个网址链接得到json值,通过以下代码获取这个json值
url = "myURL...";
StringBuilder json = new StringBuilder();
try {
URL oracle = new URL(url);
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine = null;
while ( (inputLine = in.readLine()) != null) {
json.append(inputLine);
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
return json.toString();
获得的json值为字符串:
({"response":{"level":11,"y":58451254,"x":13307843,"name":wenfa},"status":"ok"})
现在要把这个字符串转换为java对象,怎么做?
或者通过那个网址链接得到的json值怎么直接接收为java对象?
这个方法我试过,没有成功
追答怎么可能不可以,做个样例你把:
输出: