1

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

4

2 回答 2

2

是的。JSONArray 是您所需要的。

    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);
于 2015-04-01T18:47:03.910 回答
2

查看JSONArray课程。

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

您将创建一个JSONArray并在您的put命令中使用它。

于 2015-04-01T18:44:09.843 回答