Android中Json数据去掉斜杠

Android中Json数据去掉斜杠

1、build.gradle中dependencies引用。

implementation 'org.apache.commons:commons-lang3:3.7'

2、

"{\"code\":\"0\",\"data\":[{\"factweight\":\"0.00\",\"planweight\":\"15.00\",\"siteno\":\"1\",\"taskdate\":\"2022-06-29 13:36:08\",\"taskno\":\"bi20220513\",\"taskstate\":\"0\"},{\"factweight\":\"0.00\",\"planweight\":\"16.00\",\"siteno\":\"2\",\"taskdate\":\"\",\"taskno\":\"bi20220523\",\"taskstate\":\"0\"},{\"factweight\":\"0.00\",\"planweight\":\"17.00\",\"siteno\":\"3\",\"taskdate\":\"\",\"taskno\":\"bi20220524\",\"taskstate\":\"0\"}]}"

 

// 去除斜杠
String x = StringEscapeUtils.unescapeJava(responseStr);
// 去除斜杠后数据还有引号
String y = x.replace("\"{","{");
String z = y.replace("}\"","}");

 

发表回复

您的电子邮箱地址不会被公开。