【问题标题】:Spring boot RESTful service: how to post an array of JSON?Spring Boot RESTful 服务:如何发布 JSON 数组?
【发布时间】:2018-03-07 20:21:49
【问题描述】:

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

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"}]}

【问题讨论】:

  • 您可以使用typecodename 属性构建另一个类。然后让tags 成为该新类的数组。

标签: arrays json spring


【解决方案1】:
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();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-25
    • 1970-01-01
    • 2017-10-15
    • 2016-10-21
    • 2015-03-05
    • 2013-04-18
    • 1970-01-01
    • 2014-11-03
    相关资源
    最近更新 更多