Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scala.util.parsing.json.JSON
- object Test extends App {
- val tree = JSON parseFull """[10, true, "ok", {"no":"yes"}]"""
- //val tree = JSON parseFull """{
- // "x": 10,
- // "xs": [ 1, 2, 3 ],
- // "ys": { "a": "A", "b": "B" },
- // 10: 22}"""
- //> tree : Option[Any] = Some(Map(x -> 10.0, xs -> List(1.0, 2.0, 3.0), ys -> M
- //| ap(a -> A, b -> B)))
- tree match {
- case Some(map : Map[String, Any]) => {
- val keyValues = for {
- k <- map.keySet
- } yield (k.toLowerCase, map(k))
- println(keyValues)
- }
- case Some(list: List[Any]) => {
- val values = for {
- e <- list
- } yield (e, e.getClass)
- println(values)
- }
- case _ => println("JSON object needed")
- } //> Set((x,10.0), (xs,List(1.0, 2.0, 3.0)), (ys,Map(a -> A, b -> B)))
- println(matchTest("two"))
- println(matchTest("test"))
- println(matchTest(1))
- def matchTest(x: Any): Any = x match {
- case 1 => "one"
- case "two" => 2
- case y: Int => "scala.Int"
- case _ => "many"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement