获取界面返回的json问题【求助】
https://api.steampowered.com/IDOTA2Match_570/GetMatchDetails/V001/?key=D0CCA1C6B04C07BBA05F04BE6D3E8E23&match_id=173546139
这串json,为什么我用JSONObject读出来,只能取到result而且返回的是字符串,如何才能取到下面对应的一些值呢?
JSON
try{
myurl = new URL("https://api.steampowered.com/IDOTA2Match_570/GetMatchDetails/V001/?key=D0CCA1C6B04C07BBA05F04BE6D3E8E23&match_id="+matchId);
conn = myurl.openConnection();
httpURLConn = (HttpURLConnection)conn;
httpURLConn.setRequestMethod("GET");
reader = new BufferedReader(new InputStreamReader(httpURLConn.getInputStream(),"gbk"));
String lineStr = reader.readLine();
StringBuffer totalData = new StringBuffer();
while (lineStr!=null){
lineStr = reader.readLine();
totalData.append(lineStr);
}
String str = new String(totalData);
str = str.replaceAll("\t", "");
str = str.replaceAll("null", "");
str = "{"+str;
System.out.println(str);
JSONObject jsary=JSONObject.fromObject(str);//格式化成json对象
JSONObject.fromObject(str);
//JSONArray jsary=JSONArray.fromObject(str);
matchResult = jsary.getString("result");//这里读别的值都会报错
}catch (Exception e){
e.printStackTrace();
}