use of com.android.volley.toolbox.JsonArrayRequest in project TaEmCasa by Dionen.
the class JsonRequestCharsetTest method specifiedCharsetJsonArray.
@Test
public void specifiedCharsetJsonArray() throws Exception {
byte[] data = jsonArrayString().getBytes(Charset.forName("ISO-8859-2"));
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=iso-8859-2");
NetworkResponse network = new NetworkResponse(data, headers);
JsonArrayRequest arrayRequest = new JsonArrayRequest("", null, null);
Response<JSONArray> arrayResponse = arrayRequest.parseNetworkResponse(network);
assertNotNull(arrayResponse);
assertTrue(arrayResponse.isSuccess());
assertEquals(TEXT_VALUE, arrayResponse.result.getString(TEXT_INDEX));
// don't check the copyright symbol, ISO-8859-2 doesn't have it, but it has Czech characters
}
use of com.android.volley.toolbox.JsonArrayRequest in project IceNet by anton46.
the class NetworkManager method fromJsonArray.
private void fromJsonArray(final Map<String, String> headers, String requestTag, final RequestCallback requestCallback) {
JsonArrayRequest request = new JsonArrayRequest(getUrlConnection(pathUrl), new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray jsonArray) {
Object t = new Gson().fromJson(jsonArray.toString(), classTarget.getType());
if (requestCallback != null)
requestCallback.onRequestSuccess(t);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if (requestCallback != null) {
NetworkResponse response = error.networkResponse;
if (response != null)
requestCallback.onRequestError(new RequestError(response));
}
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
return headers != null ? headers : super.getHeaders();
}
};
networkHelper.addToRequestQueue(request, requestTag);
}
use of com.android.volley.toolbox.JsonArrayRequest in project FastDev4Android by jiangqqlmj.
the class Fdv_JsonArrayRequest method post.
/**
* POST请求返回JSONArray对象
* @param url 请求地址
* @param listener 请求数据返回回调接口
* @param params POST请求参数
*/
public void post(String url, final Fdv_CallBackListener<JSONArray> listener, Map<String, String> params) {
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.POST, url, null, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
if (listener != null) {
listener.onSuccessResponse(response);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if (listener != null) {
listener.onErrorResponse(error);
}
}
});
addRequest(jsonArrayRequest, params);
}
use of com.android.volley.toolbox.JsonArrayRequest in project FastDev4Android by jiangqqlmj.
the class JsonRequestCharsetTest method defaultCharsetJsonArray.
@Test
public void defaultCharsetJsonArray() throws Exception {
// UTF-8 is default charset for JSON
byte[] data = jsonArrayString().getBytes(Charset.forName("UTF-8"));
NetworkResponse network = new NetworkResponse(data);
JsonArrayRequest arrayRequest = new JsonArrayRequest("", null, null);
Response<JSONArray> arrayResponse = arrayRequest.parseNetworkResponse(network);
assertNotNull(arrayResponse);
assertTrue(arrayResponse.isSuccess());
assertEquals(TEXT_VALUE, arrayResponse.result.getString(TEXT_INDEX));
assertEquals(COPY_VALUE, arrayResponse.result.getString(COPY_INDEX));
}
use of com.android.volley.toolbox.JsonArrayRequest in project WordPress-Android by wordpress-mobile.
the class ReaderVideoUtils method requestVimeoThumbnail.
/*
* unlike YouTube thumbnails, Vimeo thumbnails require network request
*/
public static void requestVimeoThumbnail(final String videoUrl, final VideoThumbnailListener thumbListener) {
// useless without a listener
if (thumbListener == null)
return;
String id = getVimeoVideoId(videoUrl);
if (TextUtils.isEmpty(id)) {
thumbListener.onResponse(false, null);
return;
}
Response.Listener<JSONArray> listener = new Response.Listener<JSONArray>() {
public void onResponse(JSONArray response) {
String thumbnailUrl = null;
if (response != null && response.length() > 0) {
JSONObject json = response.optJSONObject(0);
if (json != null && json.has("thumbnail_large"))
thumbnailUrl = JSONUtils.getString(json, "thumbnail_large");
}
if (TextUtils.isEmpty(thumbnailUrl)) {
thumbListener.onResponse(false, null);
} else {
thumbListener.onResponse(true, thumbnailUrl);
}
}
};
Response.ErrorListener errorListener = new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
AppLog.e(T.READER, volleyError);
thumbListener.onResponse(false, null);
}
};
String url = "https://vimeo.com/api/v2/video/" + id + ".json";
JsonArrayRequest request = new JsonArrayRequest(url, listener, errorListener);
WordPress.sRequestQueue.add(request);
}
Aggregations