`
shoushounihao
  • 浏览: 39515 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

json之间的转换

 
阅读更多

public static void  wirteToJson(String fileUrl,String ss)
 {
  try {
   FileOutputStream fos=new FileOutputStream(new File(fileUrl));
   byte [] buf=new byte[1024];
   int len=0;
   try {
    fos.write(ss.getBytes());
   } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
   
  } catch (FileNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
 
 public static String readJson(String fileUrl)
 {
  StringBuilder strs=new StringBuilder();
  File file=new File(fileUrl);
  try {
   FileInputStream fis=new FileInputStream(file);
   byte [] buf=new byte[1024];
   int len=0;
   try {
    while((len=fis.read(buf))!=-1)
    {
     String ss=new String(buf,0,len);
     strs.append(ss);
    }
   } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
   
  } catch (FileNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  
  return strs.toString();
 }

 

 CommonsUtil.wirteToJson(fileUrl, jObject.toString());
   String ss=CommonsUtil.readJson(fileUrl);
   JSONObject objs=JSONObject.fromObject(ss);
   bean=(WsPendingWorkformDetailBean) com.alibaba.fastjson.JSON.parseObject(ss,WsPendingWorkformDetailBean.class);

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics