當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。