无法解析JSON格式日志

时间:2017-07-15 20:41:06

标签: json scala

我正在尝试解析我保存在一个简单文件中的JSON格式日志,但是收到错误,似乎我的记录不被识别为JSON。

def main(args: Array[String]) {
  val out = getContent("file")
  val parsedLogs = JSON.parseFull(out) match {
    case Some(x) => {
      x.asInstanceOf[List[Map[String, Any]]]
    }
  }
  for (log <- parsedLogs) {
         //do stuff
  }

def getRestContent(url: String): String = {
  scala.io.Source.fromFile(url).mkString
}

日志不一致,即每个日志可以是不同的事件,一些样本日志是

{"Event":"SparkListenerLogStart","Spark Version":"2.1.0.43"}
{"Event":"SparkListenerBlockManagerAdded","Block Manager ID":{"Executor 
ID":"driver","Host":"127.0.0.0","Port":9090},"Maximum 
Memory":956615884,"Timestamp":1499927973730}

0 个答案:

没有答案
相关问题