-1

I have a response coming from the server. When I am trying to convert the String into JSON Object, I am getting an error

 Value {
"StatusCode": "000",
"FileURI":"https:///someurl/directory/filename"
} of type java.lang.String cannot be converted to JSONObject

The code that I wrote to parse is:

JSONObject jsonObject = new JSONObject(response);

Where response is My String that is coming from server:

"{\r\n  \"StatusCode\": \"000\",\r\n  \"FileURI\": \"https://someurl/directory/filename\"\r\n}"

can anyone help me out why is it not working.

The Bat
  • 1,085
  • 1
  • 13
  • 31

1 Answers1

0

String str1 = str.replace("\r", "").replace("\n", "").replace("\\"", "");

use this code to unescape \r and \n

after removing you get the origin string

{ "StatusCode": "000", "FileURI": "https://someurl/directory/filename" }

use this link to test the string https://www.freeformatter.com/java-dotnet-escape.html#ad-output