Skip to content

Instantly share code, notes, and snippets.

@ironpeace
Created August 12, 2012 12:11
Show Gist options
  • Save ironpeace/3331625 to your computer and use it in GitHub Desktop.
Save ironpeace/3331625 to your computer and use it in GitHub Desktop.
LiftJson : list sample
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