Java 我想以动态的方式将这个json制作成表格式,如何在android中制作呢?

Java 我想以动态的方式将这个json制作成表格式,如何在android中制作呢?,java,android,json,Java,Android,Json,这是我的密码: String jsonData="{\"sem1\" :[{\"subname\":\"TOC\",\"subcode\":\"1009\",\"subcredit\":\"6\",\"subgrade\":\"AB\"},{\"subname\":\"DS\",\"subcode\":\"10090\",\"subcredit\":\"5\",\"subgrade\":\"BB\"},{\"subname\":\"TOC\",\"subcode\":\"1009\",\"sub

这是我的密码:

String jsonData="{\"sem1\" :[{\"subname\":\"TOC\",\"subcode\":\"1009\",\"subcredit\":\"6\",\"subgrade\":\"AB\"},{\"subname\":\"DS\",\"subcode\":\"10090\",\"subcredit\":\"5\",\"subgrade\":\"BB\"},{\"subname\":\"TOC\",\"subcode\":\"1009\",\"subcredit\":\"6\",\"subgrade\":\"AB\"}],\"sem2\":[{\"subname\":\"AAS\",\"subcode\":\"111009\",\"subcredit\":\"6\",\"subgrade\":\"AB\"},{\"subname\":\"AE\",\"subcode\":\"103309\",\"subcredit\":\"6\",\"subgrade\":\"DD\"}]}";

创建listview并向其添加值

 protected String doInBackground(String... params1) {

        try {
            jsonObject = new JSONObject(jsondata);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        Iterator<String> iter = jsonObject.keys();
        while (iter.hasNext()) {
            String key = iter.next();

            try {
                JSONArray jsonArray = jsonObject.getJSONArray(key);
                int length = jsonArray.length();
                for (int i = 0; i < length; i++) {
                    JSONObject jsonObject1 = jsonArray.getJSONObject(i);
                    subname = jsonObject1.getString("subname");
                    subcode = jsonObject1.getString("subcode");
                    subcredit = jsonObject1.getString("subcredit");
                    subgrade = jsonObject1.getString("subgrade");

                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }

        return null;
    }

注意:这些边框样式用于以表格形式绘制border.xml,如方框类型。

请您简单解释一下,现在还不清楚您的要求是什么,实际上我想在一个UI中显示此json,但此数据是动态生成的,仅针对一名学生,此数据因其他学生而异,那么我如何动态处理这些数据。你能理解我想说的是什么吗?不清楚你的实际问题是什么,是更新UI或解析动态json数据的问题。这些数据只针对一个学期的学生,假设我用这个数据创建这个ui,那么如果其他学生数据与这个字段不匹配,那么我的应用程序就会崩溃,所以我尝试用java编码创建一个动态ui。
 private List<YourListcontainer> listContainer = new ArrayList<YourListcontainer>();
 MyListAdapter adapter = new MyListAdapter();
 Listview lv = (ListView) rootView.findViewById(R.id.lvid);
 lv.setAdapter(adapter); 

 private class MyListAdapter extends ArrayAdapter<YourListcontainer> {

    public MyListAdapter() {
        // calls the base class constructor.
        super(context, R.layout.list_adapter, listContainer);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View itemview = convertView;
        LayoutInflater listView = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if (itemview == null) {
            itemview = listView.inflate(R.layout.list_adapter,
                    parent, false);
        }
        final YourListContainer item = listContainer.get(position);// returns the index of the cell
        TextView subject = (TextView) itemview
                .findViewById(R.id.txvsubject);
        subject.setText(item.getSubjectname());
        TextView code= (TextView) itemview
                .findViewById(R.id.txvcode);
        code.setText(item.getCode());
        TextView credit = (TextView) itemview
                .findViewById(R.id.txvcredit );
        credit .setText(item.getCredit ());
        TextView grade = (TextView) itemview
                .findViewById(R.id.txvgrade );
        grade .setText(item.getGrade ());


            subject.setBackgroundResource(R.drawable.borderstyle);
            code.setBackgroundResource(R.drawable.borderstyle);
            credit.setBackgroundResource(R.drawable.borderstyle);
            grade.setBackgroundResource(R.drawable.borderstyle);


        return itemview;
    }

}