JSONObject到ArrayList?

时间:2011-08-02 04:36:08

标签: android

我创建了一个像这样的JSON对象:

static ArrayList<item> list = new ArrayList<item>();
static {

        item dessertsItem1 = new item("name","address", "id","phone number");
        item dessertsItem2 = new item("name","address", "id","phone number");
        item dessertsItem3 = new item("name","address", "id","phone number");
}

                list.add(dessertsItem1);
        list.add(dessertsItem2);
        list.add(dessertsItem3);

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        parse();

    }

    private void parse() {
        // TODO Auto-generated method stub

        try {

            JSONObject responseObj = new JSONObject();
            for (item items : list) {

                JSONObject productObj = new JSONObject();
                productObj.put("ItemName", items.getName());
                productObj.put("ItemId", items.getId());
                productObj.put("ItemDescription", items.getDescription());
                productObj.put("ItemPrice", items.getPrice());

                Log.d("RESPONSE OBJECTS>", "the response objects are"
                        + responseObj + "\n" + productObj);
                jarray.put(productObj);
                Log.d("%%%%", "the json array is " + jarray);

            }

            responseObj.put("Desserts", jarray);
}

如何将JSONObject转换为ArrayList?

1 个答案:

答案 0 :(得分:1)

以下是一些方法。 Example 1
Example 2