On Mon, Jul 20, 2009 at 2:11 PM, fbettag <[email protected]> wrote:

>
> I still don't understand how JsObj works.. I've tried almost every
> combination, it's more like luck that some stuff i do works.
>
>        def listLanguages(): LiftResponse = {
>
>                def displayLanguage(l: Locale): (String, String) = {
>                        var r = l.getDisplayLanguage
>                        if (l.getDisplayCountry != "")
>                                r += " | " + l.getDisplayCountry
>                        return (l.toString, r)
>                }
>                JsonResponse(JsObj(
>                                "results" ->
> JsArray(Locale.getAvailableLocales.flatMap(s =>
> displayLanguage(s)) :_*)
>                ))
>        }
>
> Believe me, i tried every possible combination of JsObj in there, it
> *always* got to nag something. We really need some samples for stuff
> like that..
> One time it tells me that it needs a List(String, String), as soon as
> i have that, it want's a List(String, JsExp), so i change it to that,
> then it complains again over the first problem..
>
> it really is the big time killer for beginners to play around with
> stuff like that because the API-Docs are too "dry" to understand
> anything from it.


The best thing to do is to break your expressions out into multiple lines
and then make sure that each line has a type declaration:

So, if you've got a List[Thing] and you want a JsObj, you can work through
each of the steps.

First, define a method that will convert a Thing into a (String, JsExp):

def cvt(in: Thing): (String, JsExp) = ...

next, convert the List[Thing] into a List[(String, JsExp)]:

val lstOfPair = listOfThing.map(cvt _)

finally, create the JsObj:

JsObj(lstOfPair :_* )

When is doubt, break things up into smaller pieces and explicitly declare
the types for each piece.  That'll help you narrow things down.


>
>
> best regards.
>
>
> On 13 Jul., 18:06, David Pollak <[email protected]> wrote:
> > pushed
> >
> > On Mon, Jul 13, 2009 at 8:17 AM, David Pollak <
> [email protected]
> >
> >
> >
> > > wrote:
> >
> > > On Mon, Jul 13, 2009 at 7:18 AM, Jeppe Nejsum Madsen <[email protected]
> >wrote:
> >
> > >> Jeppe Nejsum Madsen <[email protected]> writes:
> >
> > >> > Hi,
> >
> > >> > Just figured out that while JsObj generates valid javascript
> > >> > expressions, it doesn't generate valid JSON objects since it uses
> > >> > single quotes instead of double quotes for strings.
> >
> > >> > Is there another way in Lift to generate JSON?
> >
> > >> On a slightly related note it seems as if JSONParser also accepts
> input
> > >> which is not really JSON:
> >
> > >> scala> JSONParser.parse("{'text':2}")
> > >> res0: net.liftweb.util.Box[Any] = Full(Map(text -> 2.0))
> > >> scala> JSONParser.parse("{text:2}")
> > >> res1: net.liftweb.util.Box[Any] = Full(Map(text -> 2.0))
> >
> > >> JSON requires strings to be surrounded with quotation marks (")
> >
> > >> This leads me to believe that this is all intentional :-)
> >
> > > I fixed the problem many months ago.  The fix broke some apps.  I
> backed
> > > out the fix.  I'll un-back out the fix now.
> >
> > >> /Jeppe
> >
> > > --
> > > Lift, the simply functional web frameworkhttp://liftweb.net
> > > Beginning Scalahttp://www.apress.com/book/view/1430219890
> > > Follow me:http://twitter.com/dpp
> > > Git some:http://github.com/dpp
> >
> > --
> > Lift, the simply functional web frameworkhttp://liftweb.net
> > Beginning Scalahttp://www.apress.com/book/view/1430219890
> > Follow me:http://twitter.com/dpp
> > Git some:http://github.com/dpp
> >
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

--~--~---------~--~----~------------~-------~--~----~
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