Skip to content

Instantly share code, notes, and snippets.

@nikzad-avasam
Last active April 27, 2024 17:45
Show Gist options
  • Save nikzad-avasam/ee56c2f1fba8580f34d7c609d081f02d to your computer and use it in GitHub Desktop.
Save nikzad-avasam/ee56c2f1fba8580f34d7c609d081f02d to your computer and use it in GitHub Desktop.
Use this class instead JsonArrayRequest OR JsonObjectRequest in Volley Library for support UTF-8 Languages Like Persian ( FARSI )
/**
* Created by Sam Nikzad on 5/27/2016.
*/
public class JsonArrayRequestUtf8 extends JsonArrayRequest {
public JsonArrayRequestUtf8(String url, Response.Listener<JSONArray> listener, Response.ErrorListener errorListener) {
super(url, listener, errorListener);
}
@Override
protected Response<JSONArray> parseNetworkResponse(NetworkResponse response) {
try {
String json = new String(
response.data,
"UTF-8"
);
return Response.success(
new JSONArray(json),
HttpHeaderParser.parseCacheHeaders(response)
);
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
} catch (JSONException e) {
return Response.error(new ParseError(e));
}
}
}
@nikzad-avasam
Copy link
Author

By This Class You Can Use JsonArrayReques for UTF-8 Languages Like Persian ( Farsi ) & Arabic and etc.
how to use :
create new class file in your project and copy this class codes and Now use your class name instead of JsonArrayRequest .
you can use this class instead of JsonObjectRequest Too.
پشتیبانی فارسی در کتابخانه ی Volley
Volley UTF-8 Languages Support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment