Removing a character from JSONObject?

Posted by RandomlyKnighted on Stack Overflow See other posts from Stack Overflow or by RandomlyKnighted
Published on 2012-09-23T03:33:37Z Indexed on 2012/09/23 3:37 UTC
Read the original article Hit count: 99

Filed under:
|
|
|

My JSONObject has some random characters contained within the string so I'm trying to remove them. I've tried this but with no luck.

String result = s.substring(1, s.length() - 2);
JSONObject json_data = new JSONObject(result);

if (json_data.has("["))
{
    json_data.remove("[");
}

if (json_data.has("]"))
{
    json_data.remove("]");  
}

if (json_data.has(","))
{
    json_data.remove(",");
}

It's still not removing the characters from the JSONObject. Am I checking the JSONObject for the characters incorrectly?

© Stack Overflow or respective owner

Related posts about java

Related posts about android