Created
August 12, 2012 12:11
-
-
Save ironpeace/3331625 to your computer and use it in GitHub Desktop.
LiftJson : list sample
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
object listsample { | |
def main(args: Array[String]) = { | |
val jsonstr = """ | |
{ | |
"data": [ | |
{ | |
"name": "Taro Yamada", | |
"id": "111" | |
}, | |
{ | |
"name": "Jiro Suzuki", | |
"id": "222" | |
}, | |
{ | |
"name": "Saburo Satoh", | |
"id": "333" | |
} | |
], | |
"paging": { | |
"next": "https://xxx/yyyy?limit=5000&offset=5000" | |
} | |
} | |
""" | |
val json = net.liftweb.json.parse(jsonstr) | |
for( user <- (json\"data").children ){ | |
println("user : " + (user\"name").values) | |
println("id : " + (user\"id").values) | |
} | |
val newlist = for( user <- (json\"data").children ) yield { | |
Map("name" -> (user\"name").values, "id" -> (user\"id").values ) | |
} | |
println(newlist) | |
val idlist = for( user <- (json\"data").children ) yield { | |
(user\"id").values | |
} | |
println(idlist.mkString(",")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment