Lift Web Framework

JSON Samples



Here's the code:

class Json {
  object json extends JsonHandler {
    def apply(in: Any): JsCmd =
    SetHtml("json_result", in match {
        case JsonCmd("show", _, p: String, _) => Text(p)
        case JsonCmd("textile", _, p: String, _) =>
          TextileParser.toHtml(p, Empty)
        case JsonCmd("count", _, p: String, _) => Text(p.length+" Characters")
        case x => <b>Problem... didn't handle JSON message {x}</b>
      })
  }

  def sample(in: NodeSeq): NodeSeq =
  bind("json", in,
       "script" -> Script(json.jsCmd),
       AttrBindParam("onclick",
                     Text(json.call(ElemById("json_select")~>Value,
                                    ElemById("json_question")~>Value).toJsCmd),
                     "onclick"))
}

Lift is Copyright 2007-2010 WorldWide Conferencing, LLC. Distributed under an Apache 2.0 License.
Lift version 2.3 built on Tue Apr 05 20:24:00 UTC 2011.
Stats: Total Memory: 490,274,816 Free Memory: 463,282,880 Open Sessions: 17
Updated At: Thu Jun 20 03:52:21 UTC 2013 Started At: Wed Jun 19 21:23:50 UTC 2013