java将json字符串转换成java对象

通过一个网址链接得到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对象?

你需要用额外的类库的。
可以参考下:
http://www.cnblogs.com/mailingfeng/archive/2012/01/18/2325707.html追问

这个方法我试过,没有成功

追答

怎么可能不可以,做个样例你把:

输出:

温馨提示:内容为网友见解,仅供参考
第1个回答  2015-01-09
要使用json相关的jar包。去网上搜下再下载。。。
相似回答