0
service_category_type :
[
      {parent_service_id: "5c78df0f9ed89a3ea251ad", child_service_id : "5c78df409ed89a3ea251ad"},
      {parent_service_id: "5c78dd1763f38236efdf35", child_service_id : "5c78dfb79ed89a3ea251ad"},
      {parent_service_id: "5c78dd0563f38236efdf35", child_service_id : "5c78df9c9ed89a3ea251ad"},
]

how to send this array as a parameter. I am using this link: how to send array of params using volley in android but not able to do. I need help to solve this.

1 Answer 1

1

Using this method:

public static Object mapOrListToJson(Object object) {
    if (object instanceof Map) {
        JSONObject json = new JSONObject();
        Map map = (Map) object;
        for (Object key : map.keySet()) {
            Object o = mapOrListToJson(map.get(key));
            if( o == null )
                return null;
            try {
                json.put(key.toString(), o);
            } catch (JSONException e) {
                return null;
            }
        }
        return json;
    }
    else if (object instanceof Iterable) {
        JSONArray json = new JSONArray();
        for (Object value : ((Iterable)object)) {
            Object o = mapOrListToJson(value);
            if( o == null )
                return null;
            json.put(o);
        }
        return json;
    }
    else {
        return object;
    }
}

you can transform your array into a JSONArray.

Then, you can transform it to a String representation using toString() method:

String jsonStr = myJsonArray.toString();

Finally, you can send your String to your server.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.