我收到了这种格式的回复(整个回复)
到目前为止,我已经尝试了以下代码,但出现错误
private String connect(String url) {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url);
HttpResponse response;
String returnString = null;
try {
response = httpclient.execute(httpget);
if (response.getStatusLine().getStatusCode() == 200) {
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
String res = convertStreamToString(instream);
JSONObject jsonObj = new JSONObject(res);
String f = jsonObj.getString("Result");
f = f.trim();
System.out.println("!!!!!!!!!!!!!!! "+f);
String s= jsonObj.getString("About");
System.out.println("@@@@@@ "+s);
JSONArray get = jsonObj.getJSONArray("Result");
// lets loop through the JSONArray and get all the items
for (int i = 0; i < get.length(); i++) {
// printing the values to the logcat
System.out.println("&&&&&&&&&&"+get.getJSONObject(i).getString("About").toString());
System.out.println("&&&&&&&&&&"+get.getJSONObject(i).getString("AboutMeText").toString());
}
instream.close();
}
} else {
returnString = "Unable to load page - "
+ response.getStatusLine();
}
} catch (IOException ex) {
returnString = "Connection failed; " + ex.getMessage();
} catch (JSONException ex) {
returnString = "JSON failed; " + ex.getMessage();
}
return returnString;
}
private static String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
每次我试图解析它时,它都会给我 json failed 异常,并表示没有任何价值。如果我在这里犯了任何错误,请告诉我。