Created
August 21, 2012 08:30
-
-
Save yangbajing/3413502 to your computer and use it in GitHub Desktop.
String -> JValue -> Xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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