[Lift] Re: intro to lift-json?
Hi, There's several ways to get values from JSON. 1. Use LINQ style query comprehension: for { JField(bar, JInt(x)) - json } yield x 2. Extract values with case classes implicit val formats = net.liftweb.json.DefaultFormats case class Foo(foo: Bar) case class Bar(bar: Int) json.extract[Foo] 3. XPath style val JField(bar, JInt(x)) = json \ foo \ bar Cheers Joni On 19 marras, 22:20, harryh har...@gmail.com wrote: Is there a basic intro to lift-json floating around anywhere? I'm having a bit of trouble getting started with a couple basic things. For example if a have a JObject that corresponds to: { foo : { bar : 999 } } How do I get the 999 (as an int) out of the JObject? I'm sure this is simple, just a bit confused on the basics. -harryh -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=.
Re: [Lift] Re: intro to lift-json?
I like that. But still hate JSON ;-) 2009/11/20 Joni Freeman freeman.j...@gmail.com: Hi, There's several ways to get values from JSON. 1. Use LINQ style query comprehension: for { JField(bar, JInt(x)) - json } yield x 2. Extract values with case classes implicit val formats = net.liftweb.json.DefaultFormats case class Foo(foo: Bar) case class Bar(bar: Int) json.extract[Foo] 3. XPath style val JField(bar, JInt(x)) = json \ foo \ bar Cheers Joni On 19 marras, 22:20, harryh har...@gmail.com wrote: Is there a basic intro to lift-json floating around anywhere? I'm having a bit of trouble getting started with a couple basic things. For example if a have a JObject that corresponds to: { foo : { bar : 999 } } How do I get the 999 (as an int) out of the JObject? I'm sure this is simple, just a bit confused on the basics. -harryh -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=. -- Jonas Bonér twitter: @jboner blog:http://jonasboner.com work: http://scalablesolutions.se code: http://github.com/jboner code: http://akkasource.org also:http://letitcrash.com -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=.
[Lift] Re: intro to lift-json?
You may find the Extraction tests helpful: http://github.com/dpp/liftweb/blob/master/lift-base/lift-json/src/test/scala/net/liftweb/json/ExtractionExamples.scala On Nov 19, 3:20 pm, harryh har...@gmail.com wrote: Is there a basic intro to lift-json floating around anywhere? I'm having a bit of trouble getting started with a couple basic things. For example if a have a JObject that corresponds to: { foo : { bar : 999 } } How do I get the 999 (as an int) out of the JObject? I'm sure this is simple, just a bit confused on the basics. -harryh -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=.
[Lift] Re: intro to lift-json?
Why does this parse into a JArray(List(..)) intead of a JArray(..) ? -harryh scala parse( { ids : [1, 2] } ) res5: net.liftweb.json.JsonAST.JValue = JObject(List(JField(ids,JArray (List(JInt(1), JInt(2)) On Nov 19, 3:51 pm, Tim Nelson tnell...@gmail.com wrote: Have you seen the readme file? http://github.com/dpp/liftweb/tree/master/lift-base/lift-json/ On Thu, Nov 19, 2009 at 2:20 PM, harryh har...@gmail.com wrote: Is there a basic intro to lift-json floating around anywhere? I'm having a bit of trouble getting started with a couple basic things. For example if a have a JObject that corresponds to: { foo : { bar : 999 } } How do I get the 999 (as an int) out of the JObject? I'm sure this is simple, just a bit confused on the basics. -harryh -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/liftweb?hl=. -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=.
Re: [Lift] Re: intro to lift-json?
JArray is a case class that wraps a List. It's not an array-of-list or anything, just that the actual elements are stored in a List that JArray holds. -Ross On Nov 19, 2009, at 5:12 PM, harryh wrote: Why does this parse into a JArray(List(..)) intead of a JArray(..) ? -harryh scala parse( { ids : [1, 2] } ) res5: net.liftweb.json.JsonAST.JValue = JObject(List(JField(ids,JArray (List(JInt(1), JInt(2)) On Nov 19, 3:51 pm, Tim Nelson tnell...@gmail.com wrote: Have you seen the readme file? http://github.com/dpp/liftweb/tree/master/lift-base/lift-json/ On Thu, Nov 19, 2009 at 2:20 PM, harryh har...@gmail.com wrote: Is there a basic intro to lift-json floating around anywhere? I'm having a bit of trouble getting started with a couple basic things. For example if a have a JObject that corresponds to: { foo : { bar : 999 } } How do I get the 999 (as an int) out of the JObject? I'm sure this is simple, just a bit confused on the basics. -harryh -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.comliftweb %2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/liftweb?hl=. -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/liftweb?hl= . -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=.
[Lift] Re: intro to lift-json?
Ah, ok. That makes sense. Thx! On Nov 19, 5:14 pm, Ross Mellgren dri...@gmail.com wrote: JArray is a case class that wraps a List. It's not an array-of-list or anything, just that the actual elements are stored in a List that JArray holds. -Ross On Nov 19, 2009, at 5:12 PM, harryh wrote: Why does this parse into a JArray(List(..)) intead of a JArray(..) ? -harryh scala parse( { ids : [1, 2] } ) res5: net.liftweb.json.JsonAST.JValue = JObject(List(JField(ids,JArray (List(JInt(1), JInt(2)) On Nov 19, 3:51 pm, Tim Nelson tnell...@gmail.com wrote: Have you seen the readme file? http://github.com/dpp/liftweb/tree/master/lift-base/lift-json/ On Thu, Nov 19, 2009 at 2:20 PM, harryh har...@gmail.com wrote: Is there a basic intro to lift-json floating around anywhere? I'm having a bit of trouble getting started with a couple basic things. For example if a have a JObject that corresponds to: { foo : { bar : 999 } } How do I get the 999 (as an int) out of the JObject? I'm sure this is simple, just a bit confused on the basics. -harryh -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.comliftweb %2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/liftweb?hl=. -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com . For more options, visit this group athttp://groups.google.com/group/liftweb?hl= . -- You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=.