1.隐式转化时指定匹配的字段
//由rdd格式化类型为String类型
//在toDf的过程中匹配字段
//coalesce指定了输出文件个数
//mode()指定文件的存储类型为覆盖
(tp=>(tp._1,tp._2(0),tp._2(1),tp._2(2),tp._2(3),tp._2(4),tp._2(5),tp._2(6),tp._2(7),tp._2(8),tp._2(9)))
.toDF("AttachRWBureau","allData","atpError","main","wifi","balise","TCR","speed","DMI","TIU","JRU")
.coalesce(1).().json(args(1))
2.使用gson,配合样例类来使用
json方式2 gson
(tp => {
//创建一个Gson对象
val gson = new Gson()
//调用gson对象中的方法
(AttachRWBureauKPI(tp._1, tp._2(0), tp._2(1), tp._2(2), tp._2(3), tp._2(4), tp._2(5), tp._2(6), tp._2(7), tp._2(8), tp._2(9)))
}).saveAsTextFile(args(1))
//使用了样例类
case class AttachRWBureauKPI(
AttachRWBureau: String,
allData: Int,
atpError: Int,
main: Int,
wifi: Int,
balise: Int,
TCR: Int,
speed: Int,
DMI: Int,
TIU: Int,
JRU: Int
)