Search code examples
scalaplay-json

Iterate over play jsarray


I am trying to iterate over play JsArray as below

    for (id <- myJSArray) {
      val bn = new Person(new IDM(id.asInstanceOf[String]))
      request.add(bn)
    }

but the above does not works with for each...error is cannot resolve symbol foreach


Solution

  • You can call the .value method to access a container that will work with a for loop.

    That said, there's hardly any reason to ever do that. Most things with Play-Json can be achieved in better ways. You would have to tell us more about what you're trying to do here – iterating over an array is not a goal, merely a means to an end.