我在调用restful service getDocuments
时尝试获取JSON响应
http://localhost:8080/httpConnector/Rest/Documents?Accept=application/json
def param = new HashMap();
String accept = getValue("Accept");
accept = "application/xml";
if ("application/xml".equals(accept)){
builder=new groovy.xml.MarkupBuilder(writer);
}else{
builder=new groovy.json.JsonBuilder();
}
builder.'results'() {
for(FlexiObjectAttachment foa: foaList){
for(ObjectTypeAttribute ota : otaList){
param.put(ota.getName(), foa.getFlexiObject().getByString(ota.getName()));
}
result(param);
}
}
当Accept = Accept = application / xml时,我得到以下响应,这是正确的:
<results>
<result content='' author='sdfdsf' description=' description ' link='21118' name='Dohrn' fileName='' contentType='' version='12.19.00' />
<result content='' author='ABCD' description=' description ' link='21119' name='Motor Hour Report' fileName='' contentType='' version='15.25.00' />
<result content='' author='Alex' description='Test' link='21120' name='Benzin consume' fileName='' contentType='' version='09.55.00' />
</results>
当Accept = Accept = application / json时,我也得到以下响应,这里缺少两个对象的数据。
{
"results": {
"result": {
"content": "",
"author": "Alex",
"description": "Test",
"link": "21120",
"name": "Benzin consume",
"fileName": "",
"contentType": "",
"version": "09.55.00"
}
}
}
如何将整个结果作为JSON字符串获取?