java将json字符串转换成java对象
通过一个网址链接得到json值,通过以下代码获取这个json值url="myURL...";StringBuilderjson=newStringBuilder();tr...
通过一个网址链接得到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对象? 展开
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对象? 展开
展开全部
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |