您好,登錄后才能下訂單哦!
import org.json4s.native.Serialization.{read, write} object Json2CaseClass extends App { implicit val formats = org.json4s.DefaultFormats case class Class(_name:String, students: List[Student]) case class Student(sid:String, _name:String) val s = "{\"_name\":\"Class1\",\"students\":[{\"sid\":\"1\",\"_name\":\"小明\"},{\"sid\":\"1\",\"_name\":\"小王\"}]}" val clazz:Class = read[Class](s) println(clazz) println(write(clazz)) }
<dependency> <groupId>org.json4s</groupId> <artifactId>json4s-native_2.10</artifactId> <version>3.2.11</version> <scope>${pkg}</scope> </dependency>
代碼工程:https://github.com/chocolateBlack/LearningSpark/commit/3c56dd2c89c83b99fb9b3de6d563065279ca2a0e
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。