从Scala未来的JSON响应中解析字符串列表

时间:2013-07-27 22:49:19

标签: json scala playframework

我在Scala中没有太多经验,所以我在解析我想要解析的内容方面遇到了一些麻烦。

目前,我根据访问令牌提出检索Facebook好友的请求:

val duration = Duration(10, SECONDS)
val future: Future[play.api.libs.ws.Response] = WS.url("https://graph.facebook.com/me?fields=id&access_token=" + token).get()
val response = Await.result(future, duration)

我可以通过response.json访问JSON响应。但是,朋友将按以下格式返回:

{
  "data": [
    {
      "name": "Person 1",
      "id": "1"
    },
    {
      "name": "Person 2",
      "id": "2"
    },
    {
      "name": "Person 3",
      "id": "3"
    } ...
  ],
  "paging": {  
     ...
  }
}

我知道我可以通过“(response.json \”data“)”来检索“数据”字典,但有没有办法让我以一种我可以获得所有的方式来解析这个JSON将数据中的ID作为List?

1 个答案:

答案 0 :(得分:5)

这将有效:

response.json \ "data" \\ "id"

来自\\运营商的文档:

  

查找当前对象中的fieldName和所有后代。

相关问题