Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

(Volley) How to receive Map<String,String> parameters with PHP?

hi,

I got this custom volley request class that extends Request with the request parameters in "Map<String,String>" format, my question is how to receive these parameters from the PHP side?

public class GsonGetRequest_Exp2<T> extends Request<T>
{

    private final Gson gson;
    private final Type type;
    private Map<String, String> params;
    private final Response.Listener listener;

    public GsonGetRequest_Exp2
            (String url, Type type, Map<String,String> params, Gson gson,
             Response.Listener<T> listener, Response.ErrorListener errorListener)
    {
        super(Method.GET, url, errorListener);

        this.params     = params;
        this.gson       = gson;
        this.type       = type;
        this.listener   = listener;
    }


    @Override
    public Map<String, String> getParams() {
        return params;
    }



    @Override
    protected void deliverResponse(T response)
    {
        listener.onResponse(response);
    }

    @Override
    protected Response<T> parseNetworkResponse(NetworkResponse response)
    {
        try
        {

            String json = new String(response.data, HttpHeaderParser.parseCharset(response.headers));

            return (Response<T>) Response.success
                    (
                            gson.fromJson(json, type),
                            HttpHeaderParser.parseCacheHeaders(response)
                    );
        }
        catch (UnsupportedEncodingException e)
        {
            return Response.error(new ParseError(e));
        }
        catch (JsonSyntaxException e)
        {
            return Response.error(new ParseError(e));
        }
    }

}

1 Answer

Can anyone help me with this question?