Created
December 18, 2008 19:35
-
-
Save koduki/37610 to your computer and use it in GitHub Desktop.
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
import scala.util.parsing.json._ | |
object JsonSample { | |
def main(args : Array[String]) { | |
//デフォルトは数字は浮動小数 | |
JSON.parse("""[{"test": "hello"},{"test2": {"hoge":3}}]""") match{ | |
case Some(json) => println(json) | |
} | |
//perThreadNumberParserでここから数字をBigDesimalに変換するように明示 | |
JSON.perThreadNumberParser = {input : String => BigDecimal(input)} | |
JSON.parse("""[{"test": "hello"},{"test2": {"hoge":4}}]""") match{ | |
case Some(json) => println(json) | |
} | |
// paserFullならListのTupleではなくMapになる | |
JSON.parseFull(""" { | |
"test1": "hello1", | |
"test2": "hello2", | |
"test3": "hello3" | |
}""") match{ | |
case Some(json) => println(json) | |
} | |
JSON.parseFull("""{"test2": {"hoge":5}}""") match{ | |
case Some(json) => println(json) | |
} | |
// 配列の場合はfullでもListになる | |
JSON.parseFull("""[{"test": "hello"},{"test2": {"hoge":6}}]""") match{ | |
case Some(json) => println(json) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment