Android中Json数据去掉斜杠

Posted 巫山老妖

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android中Json数据去掉斜杠相关的知识,希望对你有一定的参考价值。

数据如下:

[
  "{"STCD":"172017156159","ItemID":"0003002","TM":"2020-01-16 19:20:10","NFOINDEX":0,"DATAVALUE":0,"DATATYPE":0}",
  "{"STCD":"172017156159","ItemID":"0003003","TM":"2020-01-16 19:20:10","NFOINDEX":0,"DATAVALUE":0.8,"DATATYPE":0}"
]

  使用Java中

String str = StringEscapeUtils.unescapeJava(strmes);
android中需要引入
implementation ‘org.apache.commons:commons-lang3:3.7‘

  去除斜杠后数据还有引号“”,如

[
  "{"STCD":"172017156159","ItemID":"0003002","TM":"2020-01-16 19:20:10","NFOINDEX":0,"DATAVALUE":0,"DATATYPE":0}",
  "{"STCD":"172017156159","ItemID":"0003003","TM":"2020-01-16 19:20:10","NFOINDEX":0,"DATAVALUE":0.8,"DATATYPE":0}"
]

  使用替换

String yyyyy = kkkkkk.replace(""{","{");
String jjjjjj = yyyyy.replace("}"","}");

  这样就可以了

//Gson gson = new Gson();
                    Gson gson=new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
                    //RealDataBean realDataBean = gson.fromJson(fffff,RealDataBean.class);
                    List<RealDataBean> realDataBeanList = gson.fromJson(jjjjjj, new TypeToken<List<RealDataBean>>(){}.getType());//把JSON格式

  

以上是关于Android中Json数据去掉斜杠的主要内容,如果未能解决你的问题,请参考以下文章

如何去掉Json字符串中反斜杠

去掉双斜杠注释

C#WebAPI返回json去掉双引号前面的反斜杠

如何在android中将json数据加载到片段中

jquery 冒号转义 为啥双斜杠

如何在js中去掉json数据中的转义附