Hi Peter,
To select multiple packets you need to first select the objects within
the array. Like this:
for {
JObject(packet) - parse(s)
JField(node, JString(node)) - packet
JField(dt, JInt(dt)) - packet
JField(temp, JDouble(temp)) - packet
} yield // construct Packet here
Cheers Joni
Thanks, Joni, that works perfectly!
Peter
On Oct 5, 8:49 am, Joni Freeman freeman.j...@gmail.com wrote:
Hi Peter,
To select multiple packets you need to first select the objects within
the array. Like this:
for {
JObject(packet) - parse(s)
JField(node, JString(node)) - packet
I don't know how hard would it be to add this feature, so I don't know
if this is a reasonable request. This would make making JSON API
endpoints really easy for me and I hope for other people too.
This certainly sounds like a reasonable feature request, I will take a
deeper look at it.
Thanks, Joni.
I've been playing with just that for comprehension syntax over the
weekend. How would I do it if I had multiple packets?
{
packets: [
{
node: 00:1D:C9:00:04:9F,
dt: 1254553581405,
temp: 27.5
},
{
node: 00:1D:C9:00:04:9E,
dt: 1254553582405,
temp: 24.3
Sounds to me like you want to create yourself a small helper function
that can map that structure into your own case class, something like:
case class TempReading(node:String, dt:Int, temp:Double)
It should be possible to do this as a layer on top of the json parser.
So you can go from:
Totally untested, but something like this might work for you:
case class TempReading(node:String, dt:Int, temp:Double)
object JsonTempReading {
def unapply(obj: JObject) : Option[TempReading] {
obj match {
case JObject(List(
JField(node, JString(node)),
JField(dt,
Thanks, Kevin. I'm going to poke around with lift-json a bit more but
a case class may be the way to go.
As for the datetime, it's actually stored as a Long representing a
millisecond Unix timestamp. I've considered scala-time but haven't
seen the need to switch yet.
Peter
On Oct 3, 11:13 am,
On Sat, Oct 3, 2009 at 10:43 AM, Peter Robinett pe...@bubblefoundry.com wrote:
Thanks, Kevin. I'm going to poke around with lift-json a bit more but
a case class may be the way to go.
case classes definitely get you some juicy extras, it becomes a lot
easier to filter or map a list of
On Oct 3, 12:04 pm, Kevin Wright kev.lee.wri...@googlemail.com
wrote:
On Sat, Oct 3, 2009 at 10:43 AM, Peter Robinett pe...@bubblefoundry.com
wrote:
Thanks, Kevin. I'm going to poke around with lift-json a bit more but
a case class may be the way to go.
case classes definitely get you
On Sat, Oct 3, 2009 at 11:33 AM, Peter Robinett pe...@bubblefoundry.com wrote:
On Oct 3, 12:04 pm, Kevin Wright kev.lee.wri...@googlemail.com
wrote:
On Sat, Oct 3, 2009 at 10:43 AM, Peter Robinett pe...@bubblefoundry.com
wrote:
Thanks, Kevin. I'm going to poke around with lift-json a
10 matches
Mail list logo