我需要使用 JAVA 创建以下 JsonObject:
{
"schemas": ["urn:ietf:params:scim:api:messages:2.0:BulkRequest"],
"Operations": [{
"method": "DELETE",
"path": "/Users/955ec8cd2bfc4af8998f6f5655d3bde8?forceDelete=true"
}, {
"method": "DELETE",
"path": "/Users/97c46f642a084570a9c2fe959f8d14b3?forceDelete=true"
}, {
"method": "DELETE",
"path": "/Users/cce146e8092a4458b1297a9ebb82e980?forceDelete=true"
}]
}
我无法创建确切的 JsonObject。
创建与您的 json 对象相对应的 java POJO 类。
class TestPojo{
private List<String> schemas;
...
...
// and Getter & Setters
}
然后使用 Gson 类
TestPojo obj=new TestPojo(); //fill obj with required values
Gson gson=new Gson();
String jsonString= gson.toJson(obj); // jsonString will have JSON of class TestPojo
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句