我无法将scala xml
值解析为整数。如何解决?
错误:
NodeSq does not conform to expected type integer
代码:
import scala.io._
import scala.xml._
object Weather {
def main(args: Array[String]) {
getWeatherData()
}
def getWeatherData()={
val url = "http://api.openweathermap.org/data/2.5/weather?q=Berlin&mode=xml"
val responce = scala.io.Source.fromURL(url).mkString
val xmlResponce = XML.loadString(responce)
val kelvin: Integer = xmlResponce \\ "temperature" \\ "@value"
println( kelvin-273.15)
}
}
答案 0 :(得分:1)
(xmlResponce \\ "temperature" \\ "@value").text.toInt