-1

I am facing the issue in passing the JSON array in ion library. How can I send the send the two JSON arrays and the JSON objects in the ion library.

In the below code how can I pass the json array into the ion library.

JsonObject jsonObject = new JsonObject();
JsonArray keywordTags = new JsonArray();
for (String tagsKeyWord:tags) {
    JsonPrimitive jsonPrimitive = new JsonPrimitive(tagsKeyWord);
    keywordTags.add(jsonPrimitive);
}

jsonObject.add("tags",keywordTags);

Ion.with(this)
    .load("http://database/api/scamer-database")
    .setHeader("Authorization", authorization)
    .setTimeout(60 * 60 * 1000);

    .setMultipartParameter("city_subur",city)
    .setMultipartParameter("state",state)
    .setMultipartParameter("postalCode",postalCode)
    .setMultipartParameter("tags", jsonObject.toString() )
    .setMultipartParameter("tactics",tactic)
    .withResponse()
    .setCallback(new FutureCallback<Response<JsonObject>>() {
        @Override
        public void onCompleted(Exception e, Response<JsonObject> result) {
        }
    });

The output is like

{
  "city_subur": "Homenickside",
  "state": "Bartellside",
  "postalCode": "46228-0535",
    "tags": [
    "tag name 1",
    "tag name 2",
    "Apply Online"
  ]
  "tactic": [
    "Called me",
    "Asked My Mobile #",
    "Asked my account number"
  ]
}

How can I add the tags fields in an ion library? Please help me how to solve this.

mortalis
  • 2,060
  • 24
  • 34
Prabha Karan
  • 1,309
  • 3
  • 17
  • 35

1 Answers1

0

Set the JsonObject using .setJsonObjectBody(YOUR_JSON).

Example:

Ion.with(this)
   .load("http://database/api/scamer-database")
   .setJsonObjectBody(YOUR_JSON)
   ....

Extra Bonus: Use this library to make playing JSONs more simple.

Akshay Chordiya
  • 4,761
  • 3
  • 40
  • 52