gpt4 book ai didi

android - Android Volley 中的 JsonRequest VS StringRequest

转载 作者:太空狗 更新时间:2023-10-29 16:14:45 27 4
gpt4 key购买 nike

我正在使用 Android Volley 进行网络通话。一般我使用JSONRequest接收json数据,然后使用GSON将它们转换成对象。

new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
///Convert response.toString() to POJO using GSON
}
};

如果我使用纯字符串请求,然后使用 GSON 将字符串转换为对象,这会比 JSONRequest 更快吗?

new Response.Listener<String>() {
@Override
public void onResponse(String response) {
///Convert response to POJO using GSON
}
};

谢谢

最佳答案

使用StringRequest会更高效,因为返回的原始数据是String格式,JSONRequest将String转换成JSONObject即您的情况不需要。

其实你可以实现你自己的GSONRequest,你可以谷歌GSON volley获取很多引用。

这是一个例子: making a GSON request using volley

关于android - Android Volley 中的 JsonRequest VS StringRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32420158/

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