I am parsing a json object like this:
val product_array:Option[Any] = scala.util.parsing.json.JSON.parseFull(products_json)
var product_array2 = Array()
product_array match {
case Some(p) => {
for {
(id, desc) <- p.asInstanceOf[Map[String,Map[String,Any]]]
(propName, propValue) <- desc
} product_array2(id) ++ Array(propName->propValue.toString)
}
case None => test = "No products in shopping cart"
}
The problem is that I am trying to create a multidimensional array with this line:
product_array2(id) ++ Array(propName->propValue.toString)
But it doesn't work. How can I create a multidimensional array in the for loop?
Hopefully I can clarify:
In PHP it would be this:
product_array2[id][propName]=propValue;
product_array2(id)does not make sense, becauseidis a String. My guess is you want to convertidto an integer and use that as the outer array dimension. But it is not clear from you current formulation.Arrayis not what anyone else would recognize as an array. It's what's generally called a dictionary or a map, and it is called aMapin Scala.