I have a JSON response as follow
{
......,
"phoneNumbers":[
{
"info":[
],
"phoneNumber":"1234567890",
"phoneNumberType":"HOME_NUMBER"
},
{
"info":[
],
"phoneNumber":"9876543210",
"phoneNumberType":"WORK_NUMBER"
},
{
"info":[
],
"phoneNumber":"7418529630",
"phoneNumberType":"MOBILE_NUMBER"
}
],
.......
}
I need to extract mobile number and I try like this
val jsonBody = Json.parse(phoneListResponse.body)
val phoneList: Seq[JsValue] = (jsonBody \\ "phoneNumbers")
val mobileNodes: Seq[JsValue] = phoneList.filter(number => {
(number \\ "phoneNumberType").head.asInstanceOf[JsString].value == "MOBILE_NUMBER"
})
(mobileNodes.head \\ "phoneNumber").head.asInstanceOf[JsString].value
But my mobileNodes is empty. Any suggestion?