有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java将字符串转换为JSONArray(或任何数组)

我正在尝试将以下值参数解析为JSONArray(或任何其他数组):

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

如您所见,我将“值”作为字符串而不是实际数组获取。我如何解析这个

我尝试将其解析为JSONObject和JSONArray,但没有成功

有什么建议吗


共 (1) 个答案

  1. # 1 楼答案

    啊-我明白了(觉得自己很笨):

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