2011-08-29 53 views
2

我开发了其他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“} ]}

请帮助我获得解决这个

+0

您正在使用什么类/库转换成JSON? – Clint

+0

jersey-json-1.8.jar –

回答

0

看到http://www.flittn.com/blog/?p=146的解决方法,

+0

我用jettison 1.2替换了jettison 1.1库。但它不能解决我的问题 –

+0

解决方法是使用提供的链接中解释的自定义'ContextResolver' – 2011-08-29 11:28:22