码迷,mamicode.com
首页 > 移动开发 > 详细

Android中Json数据去掉斜杠

时间:2020-01-17 13:40:40      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:cap   lang   rom   斜杠   nbu   去除   nes   roi   create   

数据如下:

[
  "{\"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数据去掉斜杠

标签:cap   lang   rom   斜杠   nbu   去除   nes   roi   create   

原文地址:https://www.cnblogs.com/changyiqiang/p/12205137.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!