【发布时间】:2015-07-13 17:38:44
【问题描述】:
我有以下回复,我想在个人TextView 中显示所有eqid,但我不知道如何实现这一点,
下面是我从服务器获取数据并在 textview 中显示的 sn-p 代码和响应。
谁能帮我解决这个问题?
{
"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);
}
【问题讨论】:
标签: android json jsonobject