scala fastjson解析json并封装成scala类对象

package com.Trait

import com.alibaba.fastjson.JSON
import com.getsET.Get
import org.apache.log4j.LogManager
import org.apache.logging.log4j.scala.{Logger, Logging}
import org.apache.logging.log4j.Level
import scala.io.Source
//Logging是用log4j2进行的输出,配置文件在下面 
object Main extends Logging {
//下面是scala独有的样本类,在这里的作用是类封装json字符串
  case class model(stcode: Int, endurl: String, ip: String, time: Long, protrp: Int, url: String, content: String, md5: String)

  def main(args: Array[String]): Unit = {
 
    val source = Source.fromFile("C:\\Users\\Administrator\\Desktop\\11-29.txt", "UTF-8")
    for (line <- source.getLines()) {
      val obj: model = JSON.parseObject(line, classOf[model])
      if (!obj.eq(null)) {
        println(obj.md5)
        log.info(obj.md5)
//        logger.info(obj.md5)}
//      println(line)
      }
    }
   

  }
}

 

 

 

 

 

#############万恶的分割线##########万恶的分割线##############

 



    

        
            
            
                
            
            
                
                
            
            
        
    
    
    
        
            
        

        
            
        

    

你可能感兴趣的:(scala fastjson解析json并封装成scala类对象)