读出Java中的对象列表

时间:2015-03-17 16:12:10

标签: java object

您好我正在尝试读出以下内容:

enter image description here

任何人都可以帮我解释我如何需要项目的价值吗?

我已经尝试过了:

  for(int i = 0; i < ((Object[]) ret).length; i++){
                Map<String, Object> map2 = (Map<String, Object>) ret[i];
                int x = 0;
                for (Map.Entry<String, Object> entry : map2.entrySet())
                {
                    //store data in list
                    if(x == 0){
                        System.out.println(entry.getKey() + "/" + entry.getValue());
                        x++;
                    }
                    if(x==1){
                      //read out projectid

                    }
                }
            }

当我尝试输出我得到的值时:project_id / [Ljava.lang.Object; @ 41923200

已编辑:

在listview中显示数据:

private class ListViewLoaderTask extends AsyncTask<String, Void, SimpleAdapter>{

        @Override
        protected SimpleAdapter doInBackground(String... strJson) {
            connector=new OpenerpRpc(getBaseContext());
            connector.Config();
            current_page += 1;
            listOffValues = getListOffFieldValues(current_page, false, listOffValues); 

            String[] from = { "project_id"};

            int[] to = { R.id.tv_project_id};
            SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), listOffValues, R.layout.lv_gps_layout, from, to);
            return adapter;
        }
        /** Invoked by the Android on "doInBackground" is executed */
        @Override
        protected void onPostExecute(final SimpleAdapter adapter) {
            // Setting adapter for the listview
            mListView.setAdapter(adapter);

            for(int i=0;i<adapter.getCount();i++){

                HashMap<String, Object[]> hm = (HashMap<String, Object[]>) adapter.getItem(i);
                    String projectID = (String) hm.get("project_id")[1].toString();

                HashMap<String, String> hmDownload = new HashMap<String, String>();
                hmDownload.put("project_id",projectID);


                adapter.notifyDataSetChanged();

                mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
                        String listName;
                        HashMap<String, String> hmDownload = new HashMap<String, String>();
                        listName = hmDownload.get("project_id");
                        Intent myIntent = new Intent(MainActivity.this, YardActivity.class);
                        MainActivity.this.startActivity(myIntent);
                    }
                });

            }
            progress.dismiss();
            Log.d("/****","Data from odoo is finished");
        }
    }

1 个答案:

答案 0 :(得分:0)

我对你的通用类型以及ret是什么感到困惑。

我认为您的问题是地图中的值不是对象,而是对象数组 - Map<String, Object[]>。打印数组会产生"[Ljava.lang.Object;@41923200"等结果,因为数组没有toString()方法。

你应该做,例如而是hm.get("project_id")[1](假设hm被定义为Map<String, Object[]>而不是Map<String, Object>