Skip to content

Instantly share code, notes, and snippets.

@koduki
Created December 18, 2008 19:35
Show Gist options
  • Save koduki/37610 to your computer and use it in GitHub Desktop.
Save koduki/37610 to your computer and use it in GitHub Desktop.
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