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);

 

 

你可能感兴趣的:(json)