本文整理汇总了Java中com.android.volley.toolbox.HttpHeaderParser.parseCharset方法的典型用法代码示例。如果您正苦于以下问题:Java HttpHeaderParser.parseCharset方法的具体用法?Java HttpHeaderParser.parseCharset怎么用?Java HttpHeaderParser.parseCharset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.android.volley.toolbox.HttpHeaderParser
的用法示例。
在下文中一共展示了HttpHeaderParser.parseCharset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseNetworkResponse
import com.android.volley.toolbox.HttpHeaderParser; //导入方法依赖的package包/类
/**
* 通信结束后返回的回调方法.
*
* @param networkResponse 返回的响应结果对象
*/
@Override
protected Response<CommonResponse> parseNetworkResponse(NetworkResponse networkResponse) {
CommonResponse response = new CommonResponse();
// 获得字符串返回结果
String str;
try {
str = new String(networkResponse.data, HttpHeaderParser.parseCharset(networkResponse.headers));
Log.d(TAG, "return data=" + str);
// 转换返回结果为指定对象
this.doParse(str, mFormat, mTypeToken, response, mRawData);
} catch (UnsupportedEncodingException e) {
response.setCodeEnum(CodeEnum.DATA_PARSE_ERROR);
}
return Response.success(response, HttpHeaderParser.parseCacheHeaders(networkResponse));
}
示例2: parseNetworkResponse
import com.android.volley.toolbox.HttpHeaderParser; //导入方法依赖的package包/类
/**
* 通信结束后返回的回调方法.
*
* @param networkResponse 返回的响应结果对象
*/
@Override
protected Response<CommonResponse> parseNetworkResponse(NetworkResponse networkResponse) {
CommonResponse response = new CommonResponse();
// 获得字符串返回结果
String jsonString;
try {
App.getInstance().setCookie(networkResponse.headers.get(SET_COOKIE_KEY));
jsonString = new String(networkResponse.data, HttpHeaderParser.parseCharset(networkResponse.headers, OpenApi.CHARSET_UTF8));
Logger.i(jsonString);
// 转换返回结果为指定对象
this.doParse(jsonString, mFormat, mTypeToken, response, mRawData);
} catch (UnsupportedEncodingException e) {
response.setCodeEnum(CodeEnum.DATA_PARSE_ERROR);
}
return Response.success(response, HttpHeaderParser.parseCacheHeaders(networkResponse));
}
示例3: parseNetworkResponse
import com.android.volley.toolbox.HttpHeaderParser; //导入方法依赖的package包/类
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response)
{
try
{
String jsonString = new String(response.data,
HttpHeaderParser.parseCharset(response.headers));
//Allow null
if (jsonString == null || jsonString.length() == 0)
{
return Response.success(null, HttpHeaderParser.parseCacheHeaders(response));
}
return Response.success(new JSONObject(jsonString),
HttpHeaderParser.parseCacheHeaders(response));
} catch (UnsupportedEncodingException e)
{
return Response.error(new ParseError(e));
} catch (JSONException je)
{
return Response.error(new ParseError(je));
}
}
示例4: parseNetworkResponse
import com.android.volley.toolbox.HttpHeaderParser; //导入方法依赖的package包/类
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
try {
String jsonString =
new String(response.data, HttpHeaderParser.parseCharset(response.headers));
Response<JSONObject> success = Response.success(new JSONObject(jsonString),
HttpHeaderParser.parseCacheHeaders(response));
if (mProcessor != null) {
// do in background...
mProcessor.asyncProcess(mContext, success.result);
}
return success;
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
} catch (JSONException je) {
return Response.error(new ParseError(je));
} catch (Exception ex) {
Log.e(TAG, "process error!", ex);
return Response.error(new VolleyError(response));
}
}
示例5: parseNetworkResponse
import com.android.volley.toolbox.HttpHeaderParser; //导入方法依赖的package包/类
@Override
public Response<T> parseNetworkResponse(NetworkResponse response) {
String parsed;
try {
String charsetName = HttpHeaderParser.parseCharset(response.headers);
parsed = new String(response.data, charsetName);
} catch (UnsupportedEncodingException e) {
parsed = new String(response.data);
e.printStackTrace();
}
QyerResponse<T> resp = onResponse(parsed);
if (resp.isSuccess()) {
Entry entry = HttpHeaderParser.parseCacheHeaders(response);
mObjResp = Response.success(resp.getData(), entry);
return mObjResp;
} else {
return Response.error(new VolleyError(resp.getMsg()));
}
}
示例6: parseNetworkResponse
import com.android.volley.toolbox.HttpHeaderParser; //导入方法依赖的package包/类
@Override
protected Response<JSONArray> parseNetworkResponse(NetworkResponse response) {
try {
String jsonString =
new String(response.data, HttpHeaderParser.parseCharset(response.headers));
Response<JSONArray> success = Response.success(new JSONArray(jsonString),
HttpHeaderParser.parseCacheHeaders(response));
if (mProcessor != null) {
// do in background...
mProcessor.asyncProcess(mContext, success.result);
}
return success;
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
} catch (JSONException je) {
return Response.error(new ParseError(je));
} catch (Exception ex) {
return Response.error(new VolleyError(ex));
}
}
示例7: parseNetworkResponse
import com.android.volley.toolbox.HttpHeaderParser; //导入方法依赖的package包/类
@Override
protected Response<T> parseNetworkResponse(NetworkResponse response) {
try {
Map<String, String> headers = response.headers;
// TODO: 16/6/1 可以处理网络返回头信息
String parsed = "";
if (response.data != null && response.data.length > 0) {
parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers, "utf-8"));
}
T map = gson.fromJson(parsed,
new TypeToken<T>() {
}.getType());
return Response.success(map, HttpHeaderParser.parseCacheHeaders(response));
} catch (Exception je) {
return Response.error(new ParseError(je));
}
}
示例8: parseNetworkResponse
import com.android.volley.toolbox.HttpHeaderParser; //导入方法依赖的package包/类
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
try {
String resultStr = new String(response.data, HttpHeaderParser.parseCharset(response
.headers));
JSONObject jsonObject = new JSONObject(resultStr);
if (jsonObject.opt("status").equals("ok")) {
JSONObject contentObject = jsonObject.optJSONObject("post");
return Response.success(contentObject.optString("content"), HttpHeaderParser.parseCacheHeaders
(response));
} else {
return Response.success("error", HttpHeaderParser.parseCacheHeaders(response));
}
} catch (Exception e) {
e.printStackTrace();
return Response.error(new ParseError(e));
}
}
示例9: parseNetworkResponse
import com.android.volley.toolbox.HttpHeaderParser; //导入方法依赖的package包/类
@Override
protected Response<ArrayList<Picture>> parseNetworkResponse(NetworkResponse response) {
try {
String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
jsonStr = new JSONObject(jsonStr).getJSONArray("comments").toString();
ArrayList<Picture> pictures = (ArrayList<Picture>) JSONParser.toObject(jsonStr,
new TypeToken<ArrayList<Picture>>() {
}.getType());
return Response.success(pictures, HttpHeaderParser.parseCacheHeaders(response));
} catch (Exception e) {
e.printStackTrace();
return Response.error(new ParseError(e));
}
}
示例10: parseNetworkResponse
import com.android.volley.toolbox.HttpHeaderParser; //导入方法依赖的package包/类
@Override
protected Response<Token> parseNetworkResponse(NetworkResponse networkResponse) {
String data;
try {
data = new String(networkResponse.data,
HttpHeaderParser.parseCharset(networkResponse.headers));
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
}
Token.Builder token = new Token.Builder();
for (String keyValuePair : TextUtils.split(data, PATTERN_AMPERSAND)) {
String[] splitKeyValuePair = TextUtils.split(keyValuePair, PATTERN_EQUALS);
if (splitKeyValuePair.length == 2) {
addParameterToToken(token, splitKeyValuePair[0],
ParameterEncoding.decode(splitKeyValuePair[1]));
} else {
FWLog.e("Skipping malformed response parameter: %s", keyValuePair);
}
}
return Response.success(token.build(), HttpHeaderParser.parseCacheHeaders(networkResponse));
}
示例11: parseNetworkResponse
import com.android.volley.toolbox.HttpHeaderParser; //导入方法依赖的package包/类
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
String group = "";
try {
String json = new String(
response.data, HttpHeaderParser.parseCharset(response.headers));
Pattern pattern = Pattern.compile("name=\"nonce\" value=\"[A-Za-z0-9]{16}\"");
Matcher matcher = pattern.matcher(json);
if(matcher.find()){
group = matcher.group();
if(!TextUtils.isEmpty(group)){
group = group.substring(20, group.length() -1);
}
}
//name="nonce" value="[A-Za-z0-9]{16}"
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
} finally {
return Response.success(group, HttpHeaderParser.parseCacheHeaders(response));
}
}
示例12: getResponseString
import com.android.volley.toolbox.HttpHeaderParser; //导入方法依赖的package包/类
protected String getResponseString(NetworkResponse response) throws UnsupportedEncodingException {
String responseString = null;
String charset = HttpHeaderParser.parseCharset(response.headers);
if (mGzipEnabled && isGzipped(response)) {
try {
Log.d("ExtendedRequest", "decompress");
byte[] data = decompressResponse(response.data);
responseString = new String(data, charset);
} catch (IOException e) {
// it seems that result is not GZIP
}
}
if (responseString == null) {
responseString = new String(response.data, charset);
}
return responseString;
}
示例13: parseNetworkResponse
import com.android.volley.toolbox.HttpHeaderParser; //导入方法依赖的package包/类
@Override
protected Response<T> parseNetworkResponse(NetworkResponse response) {
// TODO Auto-generated method stub
try {
CommonLog.d("请求成功:statusCode:" + response.statusCode);
String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
CommonLog.d(url + "返回:" + jsonStr);
return Response.success(JSON.parseObject(jsonStr, mClazz), HttpHeaderParser.parseCacheHeaders(response));
} catch (UnsupportedEncodingException e) {
CommonLog.d("请求失败!");
return Response.error(new ParseError(e));
}
}
示例14: parseNetworkResponse
import com.android.volley.toolbox.HttpHeaderParser; //导入方法依赖的package包/类
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
String parsed;
try {
parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
} catch (UnsupportedEncodingException e) {
parsed = new String(response.data);
}
return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response));
}
示例15: parseNetworkResponse
import com.android.volley.toolbox.HttpHeaderParser; //导入方法依赖的package包/类
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
String parsed;
try {
parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
} catch (UnsupportedEncodingException e) {
parsed = new String(response.data);
}
return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response));
}