使用Scala Parser解析JSON
来源:互联网 发布:商品降价提醒软件 编辑:程序博客网 时间:2024/05/16 11:07
原博客地址:使用Scala Parser解析JSON
import scala.util.parsing.combinator._class JsonParser extends JavaTokenParsers {def jNum: Parser[Double] = floatingPointNumber ^^ (_.toDouble)def jStr: Parser[String] = stringLiteral ^^ (s => s.substring(1, s.length() - 1))def jBool: Parser[Boolean] = "(true|false)".r ^^ (_.toBoolean)def jNull: Parser[Null] = "null".r ^^ (t => null)def term = jsonArray | jsonObject | jNum | jBool | jNull | jStrdef jsonArray: Parser[List[Any]] = "[" ~> rep(term <~ ",?".r) <~ "]" ^^ (l => l)def jsonObject: Parser[Map[String, Any]] = "{" ~> rep((ident ~ ":" ~ jNum |ident ~ ":" ~ jBool |ident ~ ":" ~ jNull |ident ~ ":" ~ jsonObject |ident ~ ":" ~ jsonArray |ident ~ ":" ~ jStr) <~ ",?".r) <~ "}" ^^ {os =>var map = Map[String, Any]()os.foreach(o =>o match {case k ~ ":" ~ v => map = map ++ Map(k -> v)})map}}
object JsonParser_Ex extends JsonParser with App{val result = parseAll(jsonObject, """{a:[1,2,"a",{name:"cc"}],b:1,c:"cc",d:null,e:true}""")println(result)}
0 0
- 使用Scala Parser解析JSON
- Simplify-Core --Json解析(Json parser)
- scala 解析json字符串
- Scala解析Json字符串
- scala解析json
- scala解析json日志
- Scala解析Json格式
- scala解析JSON串
- 使用安全json parser防止json注入
- UI 13 数据解析 Parser DOM JSON
- json parser
- scala解析json数据串
- Json:scala 解析json字符串,变成对象
- 加载EasyUi和使用Parser解析器
- nodejs使用body-parser解析表单数据
- nodejs 使用cron-parser 解析cron 时间
- 使用openjdk的语法解析器(Parser)解析java源代码
- json linux c parser
- 线性表
- 设计模式(三)创建型模式
- 顺丰科技2017笔试 小C负责设计一种新的益智数字游戏
- 【DP 训练】Free Candies, UVa 10118
- 8086寄存器简述
- 使用Scala Parser解析JSON
- 子图同构问题Ullmann 算法(二)
- C++ map 容器
- console使用
- 创建和启动线程的两种方式
- Qt发布程序
- 销毁session
- C/C++(4)C调用C++方法
- centOS7通过yum安装php7.0