-3

Im trying to parse the following value paramter to a JSONArray (or any other array):

"value":"[{\"fileName\":\"Instructions.docx\",\"filePath\":\"http://someserver/api/files/somefilereference1\"},{\"fileName\":\"Sailing plan.docx\",\"filePath\":\"http://someservert/api/files/somefilereference2\"}]"

As you can see I get the "value" as a string instead of a real array. How can I parse this?

I have tried parsing it to both JSONObject and JSONArray with no success.

Any suggestions?

  • 2
    Possible duplicate of [How to parse JSON in Java](https://stackoverflow.com/questions/2591098/how-to-parse-json-in-java) – RaminS Mar 15 '19 at 21:56
  • *That* is not valid JSON, so you can't parse it with a JSON parser. Fix it to be valid JSON, e.g. surround with `{}`. Or strip off the leading `"value":"` and trailing `"`. Better yet, fix the code that generated the text, so it generates valid JSON. – Andreas Mar 15 '19 at 22:04
  • Thanks for the input, Andreas. I do not have access to the code generating the response, but I fixed it with the answer I provided. Its a workaround, but works... @Gendarme - I do not think this is a duplicate to the referenced question as this is related to convertion to a format that can be parsed. – Henrik Heggland Mar 15 '19 at 22:18
  • put here your POJO classes so that we can write the code needed for you to properly parse this JSON string – Isaac Urbina Mar 15 '19 at 22:29

1 Answers1

0

Ah - I figured it out (feels dumb):

                        String clean = propertyObject.getString("value").replaceAll("\\\\", "");

                    JSONArray docArray = new JSONArray(clean);