我无法将 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)
}
}
最佳答案
(xmlResponce\\"温度"\\"@value").text.toInt
关于java - NodeSq 不符合预期的整数类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26335351/