Created
December 18, 2013 13:21
-
-
Save txominpelu/8022212 to your computer and use it in GitHub Desktop.
Retrieving rates from json object
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
import play.api.libs.json._ | |
import play.api.libs.ws.WS | |
import scala.concurrent.ExecutionContext.Implicits._ | |
import scala.concurrent.Await | |
import scala.concurrent.duration._ | |
// Just for the example in the console - Await is WRONG | |
val result = WS.url("http://openexchangerates.org/api/latest.json?app_id=47b18507ef684bfd859ad93e21f3a226").get() | |
val json = Await.result(result, DurationInt(5).seconds).json | |
// This is the part to retrieve the keys | |
val rates = ( __ \ "rates").read[JsObject].reads(json) | |
rates.map(_.keys) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment