3

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 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?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.