私はScalaに取り組んでいます-私はJacksMapperを使用しました
import java.io.FileOutputStream
import java.io.ObjectOutputStream
import java.io.FileInputStream
import java.io.ObjectInputStream
import scala.util.Marshal
import java.io.ByteArrayOutputStream
import java.io.PrintWriter
import scala.util.parsing.json.JSONObject
import scala.util.parsing.json.JSON
import scala.util.parsing.json.JSONArray
import java.util.concurrent.atomic.AtomicReference
import scala.collection.mutable._
//import com.lambdaworks.jacks.JacksMapper
import java.io.BufferedReader
import java.io.FileReader
import net.liftweb.json._
import net.liftweb.json.JsonDSL._
import net.liftweb.json.JsonAST._
import net.liftweb.json.Extraction._
import net.liftweb.json.Printer._
//import com.codahale.jerkson.Json._
object jsonTest extends Serializable{
def main(args: Array[String]): Unit = {
var i = 1
val map = new HashMap[String, Any]() with scala.collection.mutable.SynchronizedMap[String, Any]
while(i < 10000)
{
var in_list = List[Any]()
in_list :+= "dummy"
in_list :+= "dummy"
in_list :+= "dummy"
val in_map = HashMap[String,Any]()
in_map("dummy"+i) = in_list
var out_list = List[Any]()
out_list :+= "cat1"
out_list :+= "hash1"
out_list :+= 100
out_list :+= (System.currentTimeMillis()/1000).toInt
out_list :+= in_map
map("dummy"+i) = out_list
i = i + 1
}
val json = JacksMapper.writeValueAsString[scala.collection.immutable.Map[String,Any]](map.toMap)
Some(new PrintWriter("foo.txt")).foreach{p => p.write(json); p.close}
val t1 = System.currentTimeMillis()
val br : BufferedReader = new BufferedReader(new FileReader("foo.txt"));
val sb:StringBuilder = new StringBuilder();
var line = br.readLine();
while (line != null) {
sb.append (line);
sb.append("\n");
line = br.readLine();
}
val content = sb.toString();
br.close()
println(content.length())
val obj = JacksMapper.readValue[scala.collection.immutable.Map[String,Any]](content)
val obj = scala.collection.immutable.Map[String,Any]
println(obj("dummy3"))
println(System.currentTimeMillis() - t1)
}
}
しかし、私はスカラに Lift_Json を使用しようとしています。上記のコードを Lift_Json タグで変更する方法を教えてください。Lift_Json の Jar ファイルを取得し、compact(render(json)) のような単純な解析に取り組みました。