我的JSON輸出:android系統中的ListView填充JSON
[{"FirstName":"childname2"},{"FirstName":"childname4"}]
我試圖填充我的ListView使用JSON DATAS我得到了通過使用POST方法, 通過這樣做,我有我的總JSON [{"FirstName":"childname2"},{"FirstName":"childname4"}]
在postexecute.And輸出,當我試圖通過使用循環它沒有顯示任何錯誤,,,以及不填充我的名單,, 建議通過在列表中該值,,,,
我的Java :
private ListView lv=(ListView) findViewById(R.id.listView1);
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
Toast.makeText(Certify_Child_Count.this,result, Toast.LENGTH_LONG).show();
if (result.equals("[]"))
{
Toast.makeText(Certify_Child_Count.this,
"Wrong Username or Password", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(Certify_Child_Count.this,result, Toast.LENGTH_LONG).show();
JSONArray arr=new JSONArray();
JSONObject obj = null;
//ArrayAdapter<String> adapter=new ArrayAdapter<String>(Certify_Child_Count.this, android.R.layout.simple_list_item_1, list);
//lv.setAdapter(adapter);
for(int i=0;i<arr.length();i++)
{
Toast.makeText(Certify_Child_Count.this,"going into for loop", Toast.LENGTH_LONG).show();
try {
obj=arr.getJSONObject(i);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
list.add(obj.getString("FirstName"));
Toast.makeText(Certify_Child_Count.this,obj.getString("FirstName"), Toast.LENGTH_LONG).show();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
你應該開始解析json中包含的信息 – Blackbelt
我不明白..怎麼做 – arun
我的意思是,你在試圖在谷歌上尋找它之前問? – Blackbelt