Armen Arzumanyan
Armen Arzumanyan

Reputation: 2043

Jettison JSON/java , send list of string with json request

I am creating JSON object and send over the network , like

 org.codehaus.jettison.json.JSONObject json = new org.codehaus.jettison.json.JSONObject();
                json.put("id", "15");
                json.put("code", "secret");
                json.put("type", "new type");

Also I have links of photos what I want to put into this JSON

my links like http://box.com/images/photo.jpg,http://box.com/images/photo1.jpg
http://box.com/images/photo2.jpg, http://box.com/images/photo3.jpg
As I understand I must have some list/array and put like
json.put("images", links)

How to do it, put and parse... I need one key, and list of values. Is JSON array is useful for this?

Thanks

Upvotes: 1

Views: 4338

Answers (2)

Héctor
Héctor

Reputation: 26034

Yes. JSONArray is what you need.

    List <String> links = getLinks();
    JSONArray array = new JSONArray();
    for (String link : links)
            array.put(link);

    JSONObject obj = new JSONObject();
    //put id, code, type...
    obj.put("images", array);

Upvotes: 2

Quicksilver002
Quicksilver002

Reputation: 735

Check out the JSONArray class.

http://jettison.codehaus.org/apidocs/org/codehaus/jettison/json/JSONArray.html

You'll create a JSONArray and use that in your put command.

Upvotes: 2

Related Questions