Remove quote from the JSONArray output

Ask

On the successful call, I am getting the JSONArray with the key "objects" and again the testValue with the key "name". The output is Like:

"Abcd"
"Wxyz"

My code is as follows:

public void onSuccess(JSONValue val) {
    JSONObject obj = val.isObject();
    JSONArray test = JSONUtil.getJSONArray(test, "objects");
    for (int i = 0; i < test.size(); i++) {
        JSONObject childJSONObject = (JSONObject) test.get(i);
        JSONValue testValue = childJSONObject.get("name");
        System.out.println(testValue);
    }
}

Want to print the name as following: (Without Double Quote)

Abcd
Wxyz
Vaibhav Jain

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Remove quote from the JSONArray output

From Dev

Remove JSONobject from JSONarray in Android

From Dev

Remove custom attribute from sales/quote in Magento

From Dev

How to remove a single quote from a string in oracle

From Dev

How to remove single quote from a string in R?

From Dev

Remove single quote from string using php

From Dev

remove outer quote from json array

From Dev

Remove JSON object from JSONArray - Jettison

From Dev

Java how to remove strings from JSONArray

From Dev

Remove path from output

From Dev

JSONArray from JSONArray in java

From Dev

JSONArray from JSONArray in java

From Dev

shell function issue - remove the single quote from shell statement

From Dev

How to remove a single quote from a value while inserting in SQL database

From Dev

remove backslash only from quote character using sed

From Dev

remove the single quote from json data, highchart dotnet api

From Dev

How to remove a single quote from a value while inserting in SQL database

From Dev

remove double quote from array value while saving - php

From Java

Remove all elements except one from JSONArray of JSONObjects

From Dev

How to remove duplicate and sort objects from JSONArray using Java

From Dev

Remove all elements except one from JSONArray of JSONObjects

From Dev

How to remove element from javax.json.JsonArray in java?

From Dev

How can i remove T and Z from this Jsonarray

From Dev

Razor - output single quote

From Dev

Remove input from an output stream

From Dev

remove \r\n from output

From Dev

Remove chkconfig header from output

From Dev

Remove 'u from a webscrape output

From Dev

remove trailing zeros from output

Related Related

HotTag

Archive