找到了,效率很高
import scala.collection.JavaConversions._
def json_minidev(a: Any): String = a match {
case m: Map[String, Any] => m.map {
case (name, content) => "\"" + name + "\":" + json_minidev(content)
}.mkString("{", ",", "}")
case l: List[Any] => l.map(json_minidev).mkString("[", ",", "]")
case l: java.util.List[Any] => l.map(json_minidev).mkString("[", ",", "]")
case s: String => "\"" + s + "\""
case i: Int => i.toString
} |