Spring boot RESTful service:如何发布一个 JSON 数组



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

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"}]}
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();

最新更新