Spring启动RESTful服务:如何发布JSON数组?

时间:2018-03-07 20:21:49

标签: arrays json spring

在我的服务中,我有这个类定义:

class SomeItem {
    private String item;
    private String[] tags;
    //gettter/setters
}

如何将标记字段(这是一个JSON数组)发布到服务?

{ "item": "notebook", "tags": [{"type":"region","code":"nam", "name":"nam"}, 
{"type":"author", "code":"BBB", "name":"Alex"}]}

1 个答案:

答案 0 :(得分:0)

ArrayList<JSONObject> arrayList = new ArrayList<JSONObject>();
JSONObject postedJSON = new JSONObject();

try {
    objJSON.put("key", "value");
  // add key value for json formating    
} catch (JSONException e) {
    e.printStackTrace();
}
arrayList.add(postedJSON);
String variable = arrayList.toString();