我有以下的回应,我想显示所有的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或以上或下面和那样.... –