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数据去掉斜杠的主要内容,如果未能解决你的问题,请参考以下文章