Hi David,
Does this work?
for {
user <- WorkerMgr.find(UserId(user)) ?~ "User not found"
json <- r.json
JField("messageId", JInt(messageId)) <- json
JField("timestamp", JInt(timemillis)) <- json
} yield ..
Cheers Joni
On Mar 4, 9:28 pm, David Pollak <[email protected]> wrote:
> Folks,
>
> I'm working on parsing through some JSON that's posted/put as part of a
> request. I'd like to find the messageId field and only get it if its type
> is JInt. I'm doing this within a for comprehension that has a Box at the
> top of it, so the resulting expression must play well with Box. What I've
> got is:
>
> for {
> user <- WorkerMgr.find(UserId(user)) ?~ "User not found"
> json <- r.json
> (_, messageJson) <- (json \ classOf[JField]).find(_._1 ==
> "messageId")
> messageId <- Box.asA[JInt](messageJson)
> (_, timemillisJson) <- (json \ classOf[JField]).find(_._1 ==
> "timestamp")
> timemillis <- Box.asA[JInt](timemillisJson)
> } yield ...
>
> The lines that look for messageId and timestamp and insure they are JInts
> are kinda verbose. Is there a better way to do what I'm trying to do?
>
> Thanks,
>
> David
>
> --
> Lift, the simply functional web frameworkhttp://liftweb.net
> Beginning Scalahttp://www.apress.com/book/view/1430219890
> Follow me:http://twitter.com/dpp
> Surf the harmonics
--
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.