Remove quote from the JSONArray output

Convert the JSONValue back to String:

String.ValueOf(testValue);

Or

childJSONObject.getString("name");

After all this and still end up with quotes - then fall back on RegExp.

testValue.toString().replaceAll("\"", "");

1. .replaceAll()

testValue.toString().replaceAll("\"", "");

This method replace all the double quotes which are present in your name not the first and the last.

Example : "Abcd" becomes Abcd but if the name is "Ab"cd" it should be Ab"cd according to your requirement but it becomes Abcd. Mean to say that all the double quote replaced.

2. substring()

If you want to use the substring method approach then use the following syntax to remove the first and the last double quotes from your string:

testValue.toString().subString(1,testValue.toString().length()-1);

1 - indicates the first character of the string

testValue.toString().length()-1 : indicates the last character of the string.

For your case .substring() method is more better than the .replaceAll(), if .getString() not working.

3. .ValueOf() OR .getString()

Don't know In your case why it is not working ? (may be because the string itself containing the quotes) other wise the best way is to Convert the JSONValue to the String as String.ValueOf(testValue);

OR

childJSONObject.getString("name");

Otherwise give preference as : 3 > 2 > 1


just

s.replaceAll("\"", "");

removes all " characters in your string.

or in your case

testValue.toString().replaceAll("\"", "");

This thread is pretty old, but I stumbled upon the same problem an hour ago and found the correct solution. You have to check for the type of JsonValue and if its a JsonString, you can parse it to JsonString and call its getString() method.

if(val.getValueType().equals(JsonValue.ValueType.STRING)) {
  c.setValue(((JsonString) val).getString());
} else {
  c.setValue(val.toString());
}