1

I am generating an array from json:

val product_array:Option[Any] = scala.util.parsing.json.JSON.parseFull(products_json)

And then I want to pass it to a view like this:

Ok(views.html.payment(product_array))

In the "payment.scala.html" view I am wondering what to put on the top of the view. Something like this:

@(product_array: Array)

But that is not correct. What do I put on the top of the view?

Second question:

How do I loop through that array in the view "payment.scala.html"?

1
  • Did you finally found a solution ? Commented Apr 22, 2013 at 11:17

2 Answers 2

2

I'm no Scala or Play expert so I don't know if you're able to pass an array, or if in your specific case if you're required to use an array, but I know you're allowed to pass a List[Type] so potentially you could use a List rather than an Array would be one option. If you go about it this way it would simply be

@(class_list: List[Class]

And then to traverse it would simply be

@for(class <- class_list){

And then to access the current iteration would be

@class.doStuff()
Sign up to request clarification or add additional context in comments.

Comments

1

From the documentation, for parsing, why don't you use:

val json: JsValue = Json.parse(jsonString)

and then pass it to your view, and then, navigate through the Json tree ?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.