删除使用GSON创建的JSON字符串中的双引号

时间:2018-11-29 10:47:10

标签: java apache-spark

使用GSON库后,我在spark中得到了以下结果。

[
  "{"A":"1","A-Description":"Eastern                                           "}",
  "{"B":"2","B-Description":"Western                                           "}",
  "{"C":"3","C-Description":"Northern                                          "}",
  "{"D":"4","D-Description":"Southern"}"
]

我想删除json字符串开头和结尾的双引号

最终结果如下:

[
  {"A":"1","A-Description":"Eastern                                           "},
  {"B":"2","B-Description":"Western                                           "},
  {"C":"3","C-Description":"Northern                                          "},
  {"D":"4","D-Description":"Southern"}
]

我已经解决了以下问题:

val jsonString = str.replaceAll("\\\\", "").replaceAll("\"(.+)\"", "$1")

str是一些字符串。

请提出更有效的方法。

0 个答案:

没有答案