我有以下的迴應,我想顯示所有的eqid
的個人TextView
的,但我不知道如何實現這一點, 下面是我的代碼段和響應從服務器獲取數據和顯示在textview中。
任何人都可以幫助我嗎?如何訪問json數組中的個別json對象?
{
"earthquakes":[
{
"eqid":"c0001xgp",
},
{
"eqid":"c000905e",
},
{
"eqid":"2007hear",
},
{
"eqid":"c00090da",
},
{
"eqid":"2007aqbk",
},
{
"eqid":"2007hec6",
},
{
"eqid":"a00043nx",
},
{
"eqid":"2010utc5",
},
]
}
代碼
ServiceHandler sh = new ServiceHandler();
jsonStr = sh.makeServiceCall(USER_URL, ServiceHandler.GET);
Log.d("Response: ", "> " + jsonStr);
try{
JSONObject json = new JSONObject(jsonStr);
JSONArray items = json.getJSONArray("product");
parent_layout = (RelativeLayout)findViewById(R.id.rl);
for(int i =0; i<items.length(); i++){
TextView textView = new TextView(this);
textView.setText(items.getJSONObject(i).getString(USER_NAME));
parent_layout.addView(textView);
}
看到我編輯的代碼在問題..我沒有任何錯誤..但沒有任何錯誤..但響應不顯示 – Aditya
,因爲你已經使用相對佈局你的textview將互相重疊...嘗試線性佈局或添加屬性,如layoutToLeftOf或以上或下面和那樣.... –