Android Volley中的JsonRequest VS StringRequest [英] JsonRequest VS StringRequest in Android Volley
问题描述
我正在使用Android Volley进行网络通话.通常,我使用JSONRequest接收json数据,然后使用GSON将它们转换为对象.
I am using Android Volley for network calls. Generally I use JSONRequest to receive the json data and then convert them into object using GSON.
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
///Convert response.toString() to POJO using GSON
}
};
如果我使用纯字符串请求,然后使用GSON将字符串转换为对象,那会比JSONRequest更快吗?
If I use plain string request and then convert string to objects using GSON, will that be more faster than JSONRequest?
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
///Convert response to POJO using GSON
}
};
谢谢
推荐答案
使用StringRequest
效率更高,因为返回的原始数据为String格式,JSONRequest
将String转换为JSONObject
而不是您的情况所必需的.
It would be more efficient to use StringRequest
because the raw data returned is in String format, JSONRequest
convert the String into JSONObject
which is not necessary for your case.
实际上,您可以实现自己的GSONRequest
,可以在Google GSON volley
上搜索很多参考文献.
Actually you may implement your own GSONRequest
, you can google GSON volley
for many references.
这里是一个例子: 使用齐射发出GSON请求
这篇关于Android Volley中的JsonRequest VS StringRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!