gpt4 book ai didi

java - 将具有一个元素的 Java ArrayList 转换为 JSON 对象的问题

转载 作者:行者123 更新时间:2023-11-29 09:19:45 25 4
gpt4 key购买 nike

我开发了 rest web 服务来获取 JSON 对象列表。当有多个对象时,其余 Web 服务会返回正确的 JSON 数组。但是如果只有一个对象返回 Rest web 服务不返回 JSON 数组。我想一直获取 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 Object return when having one object {"childRequest":{"childName":"test123Child","childUserName":"add"}}

JSON Object array return when having more object

{"childRequest":[{"childName":"Child ONE","childUserName":"chlid1"},{"childName":"abayakoon","childUserName":"abey"}]}

请帮我解决这个问题

最佳答案

关于java - 将具有一个元素的 Java ArrayList 转换为 JSON 对象的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7226120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com