当前位置: 首页>>代码示例>>Java>>正文


Java HttpHeaderParser.parseCharset方法代码示例

本文整理汇总了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));
}
 
开发者ID:tengbinlive,项目名称:info_demo,代码行数:21,代码来源:CommonRequest.java

示例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));
}
 
开发者ID:tengbinlive,项目名称:aibao_demo,代码行数:22,代码来源:CommonRequest.java

示例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));
	}
}
 
开发者ID:julianfalcionelli,项目名称:SimpleRESTClientHandler,代码行数:23,代码来源:BaseJsonRequest.java

示例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));
	}
}
 
开发者ID:missmisslonely,项目名称:fakeweibo,代码行数:22,代码来源:CatnutRequest.java

示例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()));
    }
}
 
开发者ID:joy-inc,项目名称:joy-library,代码行数:26,代码来源:ObjectRequest.java

示例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));
	}
}
 
开发者ID:missmisslonely,项目名称:fakeweibo,代码行数:21,代码来源:CatnutArrayRequest.java

示例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));
    }

}
 
开发者ID:jessie345,项目名称:RealArchitecture,代码行数:22,代码来源:VolleyRequest.java

示例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));
	}
}
 
开发者ID:niuzehai,项目名称:Sxumiro_AndroidClient,代码行数:22,代码来源:Request4FreshNewsDetail.java

示例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));
	}
}
 
开发者ID:ZhaoKaiQiang,项目名称:JianDan,代码行数:17,代码来源:Request4Picture.java

示例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));
}
 
开发者ID:jpd236,项目名称:fantasywear,代码行数:24,代码来源:OAuthTokenRequest.java

示例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));
    }
}
 
开发者ID:lofei117,项目名称:TuChongAndroid,代码行数:24,代码来源:WebRequest.java

示例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;
}
 
开发者ID:bugtags,项目名称:Bugtags-Android,代码行数:21,代码来源:ExtendedRequest.java

示例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));
    }
}
 
开发者ID:wangzhaosheng,项目名称:publicProject,代码行数:14,代码来源:JRYGRequest.java

示例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));
}
 
开发者ID:wondenge,项目名称:payments-Android-SDK,代码行数:11,代码来源:PostRequest.java

示例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));
}
 
开发者ID:wondenge,项目名称:payments-Android-SDK,代码行数:11,代码来源:DeleteRequest.java


注:本文中的com.android.volley.toolbox.HttpHeaderParser.parseCharset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。