val hostSQLList = jsonObj.getOrElse("hostSQLList", " ").asInstanceOf[List[String]]
var sqlRepMap = mutable.LinkedHashMap[String, Any]()
var sqlStatusMap = mutable.LinkedHashMap[String, Any]()
var sqlSlowQuery = mutable.LinkedHashMap[String, Any]()
hostSQLList.foreach(hostSQL => {
if (hostSQL != null) {
sqlRepMap ++= mutable.LinkedHashMap(hostSQL -> AlertDashboard.checkSQLReplicationLag(hostSQL))
sqlStatusMap ++= mutable.LinkedHashMap(hostSQL -> AlertDashboard.checkSQLStatus(hostSQL))
sqlSlowQuery ++= mutable.LinkedHashMap(hostSQL -> AlertDashboard.checkSQLSlowQuery(hostSQL))
}
else {
sqlRepMap ++= mutable.LinkedHashMap(hostSQL -> "Found nothing")
sqlStatusMap ++= mutable.LinkedHashMap(hostSQL -> "Found nothing")
sqlSlowQuery ++= mutable.LinkedHashMap(hostSQL -> "Found nothing")
}
})
这给了我以下输出:
{
"sqlRepMap":[
{
"_1":"xyz.com",
"_2":{
"18/09/2014 15:00:39_0":0.0,
"18/09/2014 15:30:22_0":0.0,
"18/09/2014 15:49:26_0":0.0
}
}
],
"sqlStatusMap":[
{
"_1":"xyz.com",
"_2":{
"18/09/2014 15:00:39_0":1,
"18/09/2014 15:30:22_0":1,
"18/09/2014 15:49:26_0":1
}
}
],
"sqlSlowQuery":[
{
"_1":"xyz.com",
"_2":{
"18/09/2014 15:00:39_0":0,
"18/09/2014 15:30:22_0":0,
"18/09/2014 15:49:26_0":0
}
}
]
}
当我真正想要这样的事情时:
{
"sqlRepMap":[
{
"xyz.com":{
"18/09/2014 15:00:39_0":0.0,
"18/09/2014 15:30:22_0":0.0,
"18/09/2014 15:49:26_0":0.0
}
}
],
"sqlStatusMap":[
{
"xyz.com":{
"18/09/2014 15:00:39_0":1,
"18/09/2014 15:30:22_0":1,
"18/09/2014 15:49:26_0":1
}
}
],
"sqlSlowQuery":[
{
"xyz.com":{
"18/09/2014 15:00:39_0":0,
"18/09/2014 15:30:22_0":0,
"18/09/2014 15:49:26_0":0
}
}
]
}
在普通Map中插入的相同代码给了我想要的东西但是对于LinkedHashMap它不知道如何工作。或者我的JSON ParseR可能有问题吗? 提前谢谢!