Skip to content

Instantly share code, notes, and snippets.

@yangbajing
Created August 21, 2012 08:30
Show Gist options
  • Save yangbajing/3413502 to your computer and use it in GitHub Desktop.
Save yangbajing/3413502 to your computer and use it in GitHub Desktop.
String -> JValue -> Xml
package cst
import scala.xml.{ NodeSeq, Text, Node }
import org.scalatest.FlatSpec
import org.scalatest.BeforeAndAfter
import org.scalatest.matchers.ShouldMatchers
import net.liftweb.common.{ Full, Empty, Failure, Box }
import net.liftweb.json.{ Xml, JsonAST, JsonParser }
class XmlTest extends FlatSpec with ShouldMatchers {
it should ("Json Test") in {
implicit val defaultFormats = net.liftweb.json.DefaultFormats
val ss = """{
"int": 323,
"double": 323.43,
"string": "adsf",
"bool": false,
"oo": "中华人民共和国"
"array": [
"重庆",
"江津"
]
}"""
val okResult = Xml toXml JsonParser.parse(ss)
println("okResult: " + okResult)
val errResult = JsonParser.parseOpt("{not:223}") map (Xml toXml _) getOrElse NodeSeq.Empty
println("errResult: " + errResult)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment