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


Java ParseError类代码示例

本文整理汇总了Java中com.android.volley.ParseError的典型用法代码示例。如果您正苦于以下问题:Java ParseError类的具体用法?Java ParseError怎么用?Java ParseError使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ParseError类属于com.android.volley包,在下文中一共展示了ParseError类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseNetworkResponse

import com.android.volley.ParseError; //导入依赖的package包/类
@Override
protected com.android.volley.Response<String> parseNetworkResponse(NetworkResponse response) {
    this.statusCode = response.statusCode;
    this.responseHeaders = response.headers;
    /* Get the response data */
    try {
        String json = "";
        if (response.data != null) {
            json = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        }
        String log = "%1$s\nResponse code: %2$s\nResponse body: %3$s";
        VolleyLog.v(log, getUrl(), statusCode, json);
        if (statusCode >= 200 && statusCode < 300) {
            /* Return the parsed result in a response wrapper */
            return shouldCache() ?
                    success(json, parseIgnoreCacheHeaders(response)) :
                    success(json, parseCacheHeaders(response));
        } else {
            return error(new ServerError(response));
        }
    } catch (UnsupportedEncodingException e) {
        return error(new ParseError(e));
    }
}
 
开发者ID:octaware,项目名称:super-volley,代码行数:25,代码来源:BaseRequest.java

示例2: doParse

import com.android.volley.ParseError; //导入依赖的package包/类
/**
 * The real guts of parseNetworkResponse. Broken out for readability.
 */
private Response<Bitmap> doParse(NetworkResponse response) {
    byte[] data = response.data;
    BitmapFactory.Options decodeOptions = new BitmapFactory.Options();
    Bitmap bitmap = null;
    if (mMaxWidth == 0 && mMaxHeight == 0) {
        if (mDecodeConfig != null) {
            decodeOptions.inPreferredConfig = mDecodeConfig;
        }
        bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, decodeOptions);
    } else {
        bitmap = ImageUtils.compressBitmap(data, mMaxWidth, mMaxHeight);
    }

    if (bitmap == null) {
        return Response.error(new ParseError());
    } else {
        return Response.success(bitmap, HttpHeaderParser.parseCacheHeaders(response));
    }
}
 
开发者ID:HanyeeWang,项目名称:GeekZone,代码行数:23,代码来源:BaseImageRequest.java

示例3: checkErrorType

import com.android.volley.ParseError; //导入依赖的package包/类
public static String checkErrorType(VolleyError error) {
    String str = "";
    if (error instanceof NoConnectionError) {
        str = ErrorCode.IS_NOT_NETWORK;
    } else if (error instanceof AuthFailureError) {
        str = ErrorCode.AUTH_FAILED;
    } else if (error instanceof TimeoutError) {
        str = ErrorCode.CONNECTION_TIMEOUT;
    } else if (error instanceof ParseError) {
        str = ErrorCode.PARSE_DATA_ERROR;
    } else if (error instanceof ServerError) {
        str = ErrorCode.SERVER_ERROR;
    } else if (error instanceof HttpError) {
        HttpError httpError = (HttpError) error;
        str = httpError.getMessage();
        if (TextUtils.isEmpty(str)) {
            str = ErrorCode.REQUEST_ERROR;
        }
    } else {
        str = ErrorCode.REQUEST_ERROR;
    }
    return str;
}
 
开发者ID:DoloresTeam,项目名称:dolores-android,代码行数:24,代码来源:HttpUtil.java

示例4: parseNetworkResponse

import com.android.volley.ParseError; //导入依赖的package包/类
@Override
protected Response<JSONArray> parseNetworkResponse(NetworkResponse response)
{
	try
	{
		String jsonString =
				new String(response.data, HttpHeaderParser.parseCharset(response.headers));
		return Response.success(new JSONArray(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,代码行数:18,代码来源:BaseArrayJsonRequest.java

示例5: parseNetworkResponse

import com.android.volley.ParseError; //导入依赖的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

示例6: parseNetworkResponse

import com.android.volley.ParseError; //导入依赖的package包/类
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response)
{
	try
	{
		String jsonString = new String(response.data,
				HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET));
		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,代码行数:18,代码来源:BaseMultipartJsonRequest.java

示例7: parseNetworkResponse

import com.android.volley.ParseError; //导入依赖的package包/类
@Override
protected Response<JSONArray> parseNetworkResponse(NetworkResponse response)
{
	try
	{
		String jsonString = new String(response.data,
				HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET));
		return Response.success(new JSONArray(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,代码行数:18,代码来源:BaseMultipartJsonArrayRequest.java

示例8: parseNetworkResponse

import com.android.volley.ParseError; //导入依赖的package包/类
@Override
protected Response<T> parseNetworkResponse(NetworkResponse response) {
    if (mType == null && mJavaClass == null) return Response.error(new ParseError());
    try {
        String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
        T parsedGSON = null;
        if (mType != null) {
            parsedGSON = mGson.fromJson(jsonString, mType);
        } else {
            parsedGSON = mGson.fromJson(jsonString, mJavaClass);
        }
        return Response.success(parsedGSON,
                HttpHeaderParser.parseCacheHeaders(response));
    } catch (UnsupportedEncodingException e) {
        return Response.error(new ParseError(e));
    } catch (JsonSyntaxException je) {
        return Response.error(new ParseError(je));
    }
}
 
开发者ID:yangweigbh,项目名称:VolleyX,代码行数:20,代码来源:GsonRequest.java

示例9: parseNetworkResponse

import com.android.volley.ParseError; //导入依赖的package包/类
/**
     * 数据返回
     */
    @Override
    protected Response<T> parseNetworkResponse(NetworkResponse response) {
        try {
            String strRue = new String(response.data, "UTF-8");
//            if (BuildConfig.DEBUG)
//                Log.d(TAG, xml);
            if (strRue.contains("error")) { //server返回错误
                ServerErrorResult serverError = mGson.fromJson(strRue,ServerErrorResult.class);
                Response.error(new MyErrorMessage(serverError.getStatus(),serverError.getMessage()));
            }
            return Response.success(mGson.fromJson(strRue,mClazz),HttpHeaderParser.parseCacheHeaders(response));
        } catch (Exception e) {
            e.printStackTrace();
            return Response.error(new ParseError(e));
        }
    }
 
开发者ID:yun2win,项目名称:yun2win-sdk-android,代码行数:20,代码来源:MyRequest.java

示例10: parseNetworkResponse

import com.android.volley.ParseError; //导入依赖的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

示例11: doParse

import com.android.volley.ParseError; //导入依赖的package包/类
/**
 * The real guts of parseNetworkResponse. Broken out for readability.
 */
private Response<Bitmap> doParse(NetworkResponse response) {
    Bitmap bitmap = null;
    if (response instanceof StreamBasedNetworkResponse) {
        InputStream bitmapStream = ((StreamBasedNetworkResponse) response).inputStream;
        if (bitmapStream != null) {
            //parse bitmap stream
            bitmap = doParseStreamSafe(bitmapStream, ((StreamBasedNetworkResponse) response).contentLength);
        } else {
            //parse bitmap bytes
            bitmap = doParseBytes(response.data);
        }
    } else {
        //parse bitmap bytes
        bitmap = doParseBytes(response.data);
    }

    if (bitmap == null) {
        return Response.error(new ParseError(response));
    } else {
        return Response.success(bitmap, null);
    }
}
 
开发者ID:HujiangTechnology,项目名称:RestVolley,代码行数:26,代码来源:RVImageRequest.java

示例12: parseNetworkResponse

import com.android.volley.ParseError; //导入依赖的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

示例13: parseNetworkResponse

import com.android.volley.ParseError; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected Response<T> parseNetworkResponse(NetworkResponse response) {
    try {
        if (response != null && response.data != null && response.data.length > 0) {
            if (ClientUtils.isBasicType(type)) {
                return (Response<T>) Response.success(new String(response.data, "UTF-8"),
                        HttpHeaderParser.parseCacheHeaders(response));
            } else {
                return Response.success((T) ClientUtils.getJsonReader(type).
                        readValue(response.data), HttpHeaderParser.parseCacheHeaders(response));
            }
        } else {
            return Response.success(null, HttpHeaderParser.parseCacheHeaders(response));
        }
    } catch (Exception e) {
        logger.error("JSON parsing error", e);
        return Response.error(new ParseError(e));
    }
}
 
开发者ID:Erudika,项目名称:para-client-android,代码行数:21,代码来源:ParaRequest.java

示例14: parseResponse

import com.android.volley.ParseError; //导入依赖的package包/类
@NonNull
private Response<List<SearchEntry>> parseResponse(NetworkResponse response) {
    try {
        String html = new String(response.data, parseCharset(response.headers));
        Document document = Jsoup.parse(html);
        Elements elements = document.getElementsByClass("title-detail");
        List<SearchEntry> searches = new ArrayList<>();
        for (Element element : elements) {
            Element item = element.child(0);
            SearchEntry search = new SearchEntry();
            search.url = "http://m.guokr.com" + item.attr("href");
            search.content = item.html();
            search.datetime = element.child(1).child(1).attr("datetime");
            searches.add(search);
        }
        onParseResult(searches);
        return Response.success(searches, parseCacheHeaders(response));
    } catch (Exception e) {
        return Response.error(new ParseError(e));
    }
}
 
开发者ID:drunlin,项目名称:guokr-android,代码行数:22,代码来源:SearchModelImpl.java

示例15: parseNetworkResponse

import com.android.volley.ParseError; //导入依赖的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


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