2017-10-16 66 views

回答

3

一種選擇

case class Nested(D: Long, E: String) 
case class TestClass (A: Long, B:String, C: Seq[Nested]) 

用法:

spark.read.json(sc.parallelize(
    Seq("""{"A": 123, "B": "Hello world", "C": [{"D": 123, "E": "Spark"}]}""" 
))).as[TestClass].show 

+---+-----------+-------------+ 
| A|   B|   C| 
+---+-----------+-------------+ 
|123|Hello world|[[123,Spark]]| 
+---+-----------+-------------+ 
+0

謝謝您的回答,這是運作良好。 –