我有一个json文件,我正在spark中读取。
但是,当我试图读取info列或任何子元素时,架构总是显示为null((不为空)
//reading file
val df = spark.read.json("FilePath")
df.printSchema()
root
|-- data_is: boolean (nullable = true)
|-- Student: struct (nullable = true)
| |-- Id: string (nullable = true)
| |-- JoinDate: string (nullable = true)
| |-- LeaveDate: string (nullable = true)
|-- Info: struct (nullable = true)
| |-- details: array (nullable = true)
| | |-- element: struct (containsNull = true)
| | | |-- Father_salary: double (nullable = true)
| | | |-- Mother_salary: double (nullable = true)
| | | |-- Address: String (nullable = true)
| |-- studentInfo: struct (nullable = true)
| | |-- Age: double (nullable = true)
| | |-- Name: String (nullable = true)
df.select("Student").show()
显示student元素中的字段值,即使在解析时也是如此 Student.Id
我能拿到身份证
但是每当解析信息时,我总是得到一个在文件中不为null的null值。
df.select("Info").show() // is showing as NULL
df.select("Info.detail").show() // is showing as NULL
甚至 Info.Summary
为空。
有人能建议如何得到实际的字段值而不是空值吗?
json文件
{"Student":{"JoinDate":"20200909","LeaveDate":"20200909","id":"XA12"},"Info":{"studentInfo":{"Age":13,"Name":"Alex"},"details":[{"Father_salary":1234.00,"Mother_salary":0,"Address":""}]},"data_is":true}
暂无答案!
目前还没有任何答案,快来回答吧!