Search in sources :

Example 16 with JsonArrayRequest

use of com.android.volley.toolbox.JsonArrayRequest in project android-volley by mcxiaoke.

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));
}
Also used : JsonArrayRequest(com.android.volley.toolbox.JsonArrayRequest) NetworkResponse(com.android.volley.NetworkResponse) JSONArray(org.json.JSONArray) Test(org.junit.Test)

Example 17 with JsonArrayRequest

use of com.android.volley.toolbox.JsonArrayRequest in project android-volley by mcxiaoke.

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
}
Also used : JsonArrayRequest(com.android.volley.toolbox.JsonArrayRequest) HashMap(java.util.HashMap) NetworkResponse(com.android.volley.NetworkResponse) JSONArray(org.json.JSONArray) String(java.lang.String) Test(org.junit.Test)

Aggregations

JsonArrayRequest (com.android.volley.toolbox.JsonArrayRequest)17 JSONArray (org.json.JSONArray)17 VolleyError (com.android.volley.VolleyError)10 Response (com.android.volley.Response)9 NetworkResponse (com.android.volley.NetworkResponse)7 Test (org.junit.Test)6 JSONObject (org.json.JSONObject)4 Gson (com.google.gson.Gson)3 String (java.lang.String)3 HashMap (java.util.HashMap)3 JSONException (org.json.JSONException)3 GsonBuilder (com.google.gson.GsonBuilder)2 Ticker (it.angelic.mpw.model.jsonpojos.coinmarketcap.Ticker)2 Type (java.lang.reflect.Type)2 List (java.util.List)2 Context (android.content.Context)1 Cursor (android.database.Cursor)1 MatrixCursor (android.database.MatrixCursor)1 CursorAdapter (android.support.v4.widget.CursorAdapter)1 SearchView (android.support.v7.widget.SearchView)1