我开发了其他Web服务来获取JSON对象列表。当有多个对象休息时,Web服务返回正确的JSON数组。但是,如果只有一个对象返回其他Web服务不返回JSON数组。我想一直得到JSON数组。将Java ArrayList与一个元素转换为JSON对象的问题
我休息服务的方法有一个对象 时
@GET
@Produces("application/json")
@Path("/chekinList")
public List<LocationReguest> getChekinList(@QueryParam("childID") String userName, @QueryParam("appkey") String appkey, @QueryParam("appPassword") String appPassword) {
LocationController locationController = new LocationController();
List<LocationReguest> locreqlist = locationController.getChekinList(userName);
//TODO return proper representation object
return locreqlist;
}
JSON对象返回{ “childRequest”:{ “childName”: “test123Child”, “childUserName”: “添加”}}
JSON对象数组返回具有多个对象时
{ “childRequest”:[{ “childName”: “儿童 ONE”, “childUserName”: “chlid1”},{ “childName”: “abayakoon”,” childUserName “:” abey“} ]}
请帮助我获得解决这个
您正在使用什么类/库转换成JSON? – Clint
jersey-json-1.8.jar –