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格式
相关推荐
SXIAOYI 2020-09-16
xiaonuoyal 2020-06-17
SXIAOYI 2020-06-11
yinbaoshiguang 2020-06-09
Chydar 2020-06-02
nalanrumeng 2020-06-01
xiaonuoyal 2020-06-01
nalanrumeng 2020-05-19
ITprivate 2020-04-15
xiaonuoyal 2020-04-14
ITprivate 2020-03-26
ITprivate 2020-02-12
nalanrumeng 2020-01-13
xiaonuoyal 2019-12-07
xiaonuoyal 2019-11-18
TOmyhonour 2019-11-16
csdnxpw 2019-11-12