gpt4 book ai didi

android - Google Cloud Endpoints 无法返回 Map(而是返回 JsonMap)

转载 作者:太空狗 更新时间:2023-10-29 15:07:45 25 4
gpt4 key购买 nike

Google Cloud Endpoints 返回 JsonMap而不是我的服务器端 Map<Long,Long> . 我怎样才能得到 Map<Long,Long> ?

在 Google App Engine 端,我定义了一个返回 map 的 Google 云端点:

@ApiMethod(path="somebendpoint/somename")
public Map<Long, Long> getSomething(@Named("x")int x, User user){
Map<Long, Long> map = ...
return map;
}

在 Android 客户端,我用

wEndpoint.wEndpoint().getSomething(x).execute();

但是返回类型是JsonMap ,即 Map<String,Object> .

---

--- 编辑(将 map 包装在包装类中似乎也不起作用)

我在服务器端将 Map 包装在一个包装器类中,如下所示:

public class WrapperMap implements Serializable {
private Map<Long, Long> wrapperMap;
public WrapperMap(){
}
public setMap(Map<Long, Long> map){
wrapperMap = map;
}
public Map<Long, Long> getMap(){
return wrapperMap;
}
}

但仍然在客户端,当我这样做时:

WrapperMap temp = wEndpoint.wEndpoint().getSomething(x).execute();

temp.getMap()返回 JsonMap , 不是 Map<Long,Long>

谢谢

最佳答案

使用端点,您不必自己处理 JSON 或反 JSON - 端点会为您完成。但我认为您需要将您的 map 包装在一个类中才能使其工作,请参阅 this post .

关于android - Google Cloud Endpoints 无法返回 Map(而是返回 JsonMap),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20257294/

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