开发者

JSONObject to ArrayList?

I have created a JSON object like this:

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 开发者_C百科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);
}

How do I convert the JSONObject to an ArrayList?


Here are some ways to do it. Example 1
Example 2

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜