Skip to content

Instantly share code, notes, and snippets.

@haiy
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haiy/6a16e14ac4b969a7eb75 to your computer and use it in GitHub Desktop.
Save haiy/6a16e14ac4b969a7eb75 to your computer and use it in GitHub Desktop.
json scala simple
import java.util
import org.scalatest.FunSuite
import scala.util.parsing.json._
import org.json.JSONObject
import scala.collection.JavaConverters._
/**
* Created by haiy on 5/21/15.
*/
class TestIO extends FunSuite {
test("read json") {
val result = JSON.parseFull( """
{"title":"淘宝清仓特价甩卖 夏季青花瓷印花泡泡袖淑女修身弹力针织连衣裙","property":{"尺码":"S M L XL","流行元素/工艺":"蝴蝶结","裙型":"铅笔裙","腰型":"中腰","材质":"涤纶","款式":"其他款式","通勤":"淑女","成分含量":"91%(含)-95%(含)","袖长":"短袖","组合形式":"单件","袖型":"泡泡袖","风格":"通勤","年份季节":"2014春季","裙长":"短裙","主图来源":"自主实拍图","颜色分类":"兰花","货号":"Q11016","品牌":"OWANGANNA","衣门襟":"套头","领型":"圆领","图案":"花色","面料":"针织"},"catId":"50010850","showPrice":"198.00","itemId":"tbi10012672863","brandName":"OWANGANNA"}
""")
result match {
case Some(e) => println(e) // => Map(name -> Naoki, lang -> List(Java, Scala))
case None => println("Failed.")
}
}
test("tojson") {
val testMap1: util.Map[String, String] = Map("t1" -> "v1").asJava
val testMap2: util.Map[String, Object] = Map("t2" -> "v2", "t3" -> testMap1).asJava
val jo = new JSONObject(testMap2)
println(jo.toString())
}
}
@haiy
Copy link
Author

haiy commented May 26, 2015

maven repo: [http://mvnrepository.com/artifact/org.json/json]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment