Android 如何从twitter搜索响应解析JSON
这是我用于twitter搜索的url 如何获取响应对象?我知道如何解析一个JSON对象,这是相同的方式吗Android 如何从twitter搜索响应解析JSON,android,twitter,Android,Twitter,这是我用于twitter搜索的url 如何获取响应对象?我知道如何解析一个JSON对象,这是相同的方式吗 谢谢 尝试使用BufferedReader和StringBuilder(这就是我当前在应用程序中使用的)。然后,我使用该字符串创建一个JSONObject。以下是您可以使用的一些模板代码: try{ HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(//YOUR URL
谢谢 尝试使用BufferedReader和StringBuilder(这就是我当前在应用程序中使用的)。然后,我使用该字符串创建一个JSONObject。以下是您可以使用的一些模板代码:
try{
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(//YOUR URL STRING HERE);
HttpResponse response;
response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
InputStream in = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder sb = new StringBuilder();
String input = null;
try {
while ((input = reader.readLine()) != null) {
sb.append(input + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
String enter = sb.toString();
JSONObject obj = new JSONObject(enter);
//DO WHATEVER YOU WANT WITH THE JSONObject here
in.close();
} catch(MalformedURLException e){
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e){
e.printStackTrace();
}
注意,这使用了org.jsontanks-Vinay下的简单JSON库,我不知道我应该这么做。