我有一個Twitter的飼料的URL,我已經創建了一個字符串,我想把它放在一個JSONArray,所以我可以回電各個項目。在這種情況下 - 「文本」。Android Twitter字符串到Json數組
這裏是我的代碼:
try {
// Create a new HTTP Client
DefaultHttpClient defaultClient = new DefaultHttpClient();
// Setup the get request
HttpGet httpGetRequest = new HttpGet(
"https://api.twitter.com/1/statuses/user_timeline.json?screen_name=evostikleague&count=10");
// Execute the request in the client
HttpResponse httpResponse = defaultClient.execute(httpGetRequest);
// Grab the response
BufferedReader reader = new BufferedReader(new InputStreamReader(
httpResponse.getEntity().getContent(), "UTF-8"));
String json = reader.readLine();
// Instantiate a JSON object from the request response
JSONObject obj = new JSONObject(json);
List<String> items = new ArrayList<String>();
JSONArray jArray = obj.getJSONArray(json);
for (int i = 0; i < jArray.length(); i++) {
JSONObject oneObject = jArray.getJSONObject(i);
items.add(oneObject.getString("text"));
Log.i("items", "items");
}
setListAdapter(new ArrayAdapter<String>(this, R.layout.single_item,
items));
ListView list = getListView();
list.setTextFilterEnabled(true);
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),
((TextView) arg1).getText(), 1000).show();
}
});
} catch (Exception e) {
// In your production code handle any errors and catch the individual exceptions
e.printStackTrace();
}
有什麼問題可以找到? – MByD 2012-03-11 14:05:25
它不顯示我的列表視圖中的任何東西我在我的LogCat中得到一個JSONeexception。 – iamlukeyb 2012-03-11 14:15:26