"[email protected]" <[email protected]> writes:

> Hi
> i need some help with a conversation from HashMap to JsArray.
>
> I have something like:
>
> var m = new HashMap[String, (Int,Int)]
>
> and i want to use it in JE.Call as an argument. I think it has to be
> converted to a JsArray. Some kind of map or fold should fit here, but
> i dont know how to do it.
> The JSON should look like [{"str1":[1,2]},{"str2":[1,2]}] or any
> similar.
>
> Thanks for your tipps. (maybe its more a scala issue but i try it :))

This works, but looks rather ugly :-)

scala> val m = Map() ++ List("s" -> (1,2), "t" -> (3,4))                        
      
m: scala.collection.immutable.Map[java.lang.String,(Int, Int)] = Map(s
-> (1,2), t -> (3,4))

scala> JsArray(m.map(x => JsObj(x._1 -> JsArray(x._2._1, 
x._2._2))).toList:_*).toJsCmd
res20: String = 
[{"s": [1, 2]
}, {"t": [3, 4]
}]

/Jeppe
-- 
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en.


Reply via email to