"people": [
{
"name": "Jack",
"age": 15
},
{
"name": "Tony",
"age": 23
},
{
"name": "Mike",
"age": 19
}
]
Thats a sample of the json i'm trying to parse through. I want to be able to do a foreach operation on each person and println their name and age.
I know how to handle json arrays when it's a single item or a specific numbered item. I don't know how to iterate through all items.
Can anyone help me out?
If you don't have the object type you can use
.as[List[JsValue]]
Then access each element like usual
There are many ways to do this with the Play JSON Library. The main difference is the usage of Scala case class or not.
Given a simple json
You can use case class and Json Macro to automatically parse the data
Or without case class, manually
In other words, check the very complete documentation on this subject :) http://www.playframework.com/documentation/2.1.0/ScalaJson