数据如下:
[ "{\"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格式
原文地址:https://www.cnblogs.com/changyiqiang/p/12205137.html
时间: 2024-10-04 07:18:56