diff options
author | michelou <michelou@epfl.ch> | 2007-11-09 16:47:15 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2007-11-09 16:47:15 +0000 |
commit | a49aba6e8275d78d13003a959b240a4c8e4fca5b (patch) | |
tree | fc2b7e4e4e9c61b373df94e6176092bb5b4c3333 /test/files/run/json.scala | |
parent | 35bd7a8255fb8c00b3dd08932a224e68a5ae2bfb (diff) | |
download | scala-a49aba6e8275d78d13003a959b240a4c8e4fca5b.tar.gz scala-a49aba6e8275d78d13003a959b240a4c8e4fca5b.tar.bz2 scala-a49aba6e8275d78d13003a959b240a4c8e4fca5b.zip |
fixed ticket #136 (cnt'd)
Diffstat (limited to 'test/files/run/json.scala')
-rw-r--r-- | test/files/run/json.scala | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/files/run/json.scala b/test/files/run/json.scala new file mode 100644 index 0000000000..040dbd380e --- /dev/null +++ b/test/files/run/json.scala @@ -0,0 +1,60 @@ +import scala.util.parsing.json._ + +object Test extends Application { + def printJSON(s: String) { + println(JSON parse s) + } + printJSON("{\"name\": \"value\"}") + printJSON("{\"name\": \"va1ue\"}") // ticket #136 + printJSON("{\"name\": { \"name1\": \"va1ue1\", \"name2\": \"va1ue2\" } }") + println + + // from http://en.wikipedia.org/wiki/JSON + val sample1 = """ +{ + "firstName": "John", + "lastName": "Smith", + "address": { + "streetAddress": "21 2nd Street", + "city": "New York", + "state": "NY", + "postalCode": 10021 + }, + "phoneNumbers": [ + "212 732-1234", + "646 123-4567" + ] +}""".mergeLines + //println(sample1) + printJSON(sample1) + println + + // from http://www.developer.com/lang/jscript/article.php/3596836 + val sample2 = """ +{ + "fullname": "Sean Kelly", + "org": "SK Consulting", + "emailaddrs": [ + {"type": "work", "value": "kelly@seankelly.biz"}, + {"type": "home", "pref": 1, "value": "kelly@seankelly.tv"} + ], + "telephones": [ + {"type": "work", "pref": 1, "value": "+1 214 555 1212"}, + {"type": "fax", "value": "+1 214 555 1213"}, + {"type": "mobile", "value": "+1 214 555 1214"} + ], + "addresses": [ + {"type": "work", "format": "us", + "value": "1234 Main StnSpringfield, TX 78080-1216"}, + {"type": "home", "format": "us", + "value": "5678 Main StnSpringfield, TX 78080-1316"} + ], + "urls": [ + {"type": "work", "value": "http://seankelly.biz/"}, + {"type": "home", "value": "http://seankelly.tv/"} + ] +}""".mergeLines + //println(sample2) + printJSON(sample2) + println +} |