Created
March 30, 2014 17:14
-
-
Save riccardomerolla/9876170 to your computer and use it in GitHub Desktop.
scala-json-getValue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val jsonString = """{"count":100205,"_shards":{"total":5,"successful":5,"failed":0}}""" | |
val tweets = scala.util.parsing.json.JSON.parseFull(jsonString) | |
def getValue(parsedJson: Option[Any], key: String): Double = { | |
parsedJson match { | |
case Some(m: Map[String, Any]) => m(key) match { | |
case d: Double => d | |
} | |
} | |
} | |
getValue(tweets, "count") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment