-12

Below is my JSON

["[0288144111, Please check File Values:==>For input string: "N/A", 20180201]","[4403244111, Upload Not Received, 20180201]","[4246244111, Upload Not Received, 20180201]","[7097244111, Upload Not Received, 20180201]","[9917244111, Upload Not Received, 20180201]"]

I am using replaceAll("[\\\\/:*#?<>|=]", "") . I am still getting JSONException due to quotes in "NA". How can I make sure I just replace quotes around NA and not in the whole input string.

Edit

response:

{"tag":"fetchupdDetailStatus","status":true,"uploadDetails":"[\"[0288144111, Please check File Values:==>For input string: \\\"#N\\\/A\\\", 20180201]\",\"[4403244111, Upload Not Received, 20180201]\",\"[4246244111, Upload Not Received, 20180201]\",\"[7097244111, Upload Not Received, 20180201]\",\"[9917244111, Upload Not Received, 20180201]\"]"}

Code:

JSONObject jObj = new JSONObject(response);
if (jObj != null) {
 System.out.println("RESPONSE1===>" + jObj.getString("uploadDetails"));
 String uploadDetails = jObj.getString("uploadDetails");
 String jsonFormattedString = uploadDetails.replaceAll("\\\\", "").replaceAll("[\\\\/:*#?<>|=]", ""); 
 System.out.println("Formatted String getFurtherDetails ==>"+jsonFormattedString);
 jsonArrayUD = new JSONArray(jsonFormattedString);  //getting org.json.JSONException: Unterminated array at character 58
}

O/P:

RESPONSE1===>["[0288144111, Please check File Values:==>For input string: \"#N\/A\", 20180201]","[4403244111, Upload Not Received, 20180201]","[4246244111, Upload Not Received, 20180201]","[7097244111, Upload Not Received, 20180201]","[9917244111, Upload Not Received, 20180201]"]
Formatted String getFurtherDetails ==>["[0288144111, Please check File ValuesFor input string "NA", 20180201]","[4403244111, Upload Not Received, 20180201]","[4246244111, Upload Not Received, 20180201]","[7097244111, Upload Not Received, 20180201]","[9917244111, Upload Not Received, 20180201]"]
aminography
  • 21,986
  • 13
  • 70
  • 74

1 Answers1

-1

Your problems are surely coming from the fact that the double quotes weren't escaped from the beginning. According to the docs, you should be using JSONObject#quote:

quote

String quote (String data)

Encodes data as a JSON string. This applies quotes and any necessary character escaping.

Parameters
data String: the string to encode. Null will be interpreted as an empty string.

lejlun
  • 4,140
  • 2
  • 15
  • 31
DJDaveMark
  • 2,669
  • 23
  • 35