本文介绍了把ArrayList的进入参数的JSONObject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须做我请求与排球框架。这是JSONObject的POST请求。

我必须通过一根弦和一个JSONArray..but我怎么可以?

我开始这样的:

 私人字符串mUrl;
    私人的ArrayList<字符串> mUrlDove;

  HashMap的<字符串,字符串> PARAMS =新的HashMap<字符串,字符串>();
            params.put(URL,mUrl);
            params.put(urlDove,mUrlDove); --->错了,因为mUrlDove不是一个字符串


            mUrl = app.getInstance()getmUrlRestWS()+的getString(R.string.path)。

            JsonObjectRequest mRequest =新JsonObjectRequest(
                    mUrl,新的JSONObject(PARAMS)
                    createMyReqSuccessListener(),
                    createMyReqErrorListener()){
                @覆盖
                公共地图<字符串,字符串> getHeaders()抛出AuthFailureError {
                    返回app.getInstance()createBasicAuthHeader()。
                }
            };
 

如果我尝试用浏览器,我必须设置这样的:

  {
  URL:www.secret.com
  urlDove:www.google.com,www.yahoo.com]
}
 

解决方案

您需要做一个JSON数组,然后再存储

 私人字符串mUrl;
私人的ArrayList<字符串> mUrlDove;

HashMap的<字符串,字符串> PARAMS =新的HashMap<字符串,字符串>();
        params.put(URL,mUrl);
        JSONArray jsArray =新JSONArray(mUrlDove);
        params.put(urlDove,jsArray.toString());

        mUrl = app.getInstance()getmUrlRestWS()+的getString(R.string.path)。

        JsonObjectRequest mRequest =新JsonObjectRequest(
                mUrl,新的JSONObject(PARAMS)
                createMyReqSuccessListener(),
                createMyReqErrorListener()){
            @覆盖
            公共地图<字符串,字符串> getHeaders()抛出AuthFailureError {
                返回app.getInstance()createBasicAuthHeader()。
            }
        };
 

i must do i request with Volley Framework. This is a POST request with JSONObject.

I must pass one string and one JSONArray..but how i can?

I start with this:

 private String mUrl;
    private ArrayList<String> mUrlDove;

  HashMap<String, String> params = new HashMap<String, String>();
            params.put("url", mUrl);
            params.put("urlDove", mUrlDove); ---> Wrong because mUrlDove is not a String


            mUrl = app.getInstance().getmUrlRestWS() + getString(R.string.path);

            JsonObjectRequest mRequest = new JsonObjectRequest(
                    mUrl, new JSONObject(params),
                    createMyReqSuccessListener(),
                    createMyReqErrorListener()) {
                @Override
                public Map<String, String> getHeaders() throws AuthFailureError {
                    return app.getInstance().createBasicAuthHeader();
                }
            };

If i try with Browser i must set this:

{
  "url": "www.secret.com",
  "urlDove" : [ "www.google.com","www.yahoo.com"]
}
解决方案

you need to make a JSON Array first and then store that

private String mUrl;
private ArrayList<String> mUrlDove;

HashMap<String, String> params = new HashMap<String, String>();
        params.put("url", mUrl);
        JSONArray jsArray = new JSONArray(mUrlDove);
        params.put("urlDove", jsArray.toString()); 

        mUrl = app.getInstance().getmUrlRestWS() + getString(R.string.path);

        JsonObjectRequest mRequest = new JsonObjectRequest(
                mUrl, new JSONObject(params),
                createMyReqSuccessListener(),
                createMyReqErrorListener()) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                return app.getInstance().createBasicAuthHeader();
            }
        };

这篇关于把ArrayList的进入参数的JSONObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 15:33