1

I have list of items adding in to JsonArray and convert this JsonArray to string and adding this string JsonObject as a property. But While I am getting response is with back slashs.

jsonObject.addProperty("name",rsmd.getColumnLabel(1));
JsonArray itemJsonArray = new JsonArray();
JsonArray jsonArray = new JsonArray();

while (resultSet.next()) {
   itemJsonArray.add(resultSet.getString(1));
}

jsonObject.addProperty("items",itemJsonArray.toString());         
jsonArray.add(jsonObject);

Output:

{
    "name": "username",
    "items": [\"Mohan\",\"Mohan\",\"Mohan\"]             
}
1

1 Answer 1

2

Basically your problem is you are doing itemJsonArray.toString() and also you need to use add() instead of addProperty(), so:

Instead of

jsonObject.addProperty("items",itemJsonArray.toString());

Do this:

jsonObject.add("items",itemJsonArray);
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.