Search code examples
androidjsonandroid-volleyandroidhttpclientandroid-json

Posting Json object as parameter with http


I need to post some data to a server in this format

dates: [{...},{...},{...}]

So far I have done this

for(RepeatEventItem item : selected_dates){
   pEntity.addPart("dates[]", new StringBody(mapper.writeValueAsString(item)));
}

and the resulting format is this

["{...}","{...}"]

how can I get rid of the quotes as the server is expecting JSONObjects in the array not strings


Solution

  • You can do this with a two dimensional array

    for(int i = 0; i < selectdated_dates.size(); i++){
        RepeatEventItem item = selected_dates.get(i);
        pEntity.addPart("dates["+i+"][]", new StringBody(mapper.writeValueAsString(item)));
    }
    

    The result will be in the format you want.