0
http://search.twitter.com/search.json?page=10&q=&geocode=37,-122,1mi&callback=myCallback如何從twitter搜索響應中解析JSON
這是我的twitter搜索的網址。
如何獲取響應對象?我知道如何解析一般的JSON對象,它是一樣的嗎?
謝謝!
http://search.twitter.com/search.json?page=10&q=&geocode=37,-122,1mi&callback=myCallback如何從twitter搜索響應中解析JSON
這是我的twitter搜索的網址。
如何獲取響應對象?我知道如何解析一般的JSON對象,它是一樣的嗎?
謝謝!
嘗試使用BufferedReader和StringBuilder(這就是我目前用於我的應用程序)。然後我使用String來創建一個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.json – Vinay
感謝維奈簡單JSON庫,我不知道我應該做的。 – Archie
沒有問題broski。 – Vinay