我在我的scala代码中使用了JSON库net.sf.json(http://json-lib.sourceforge.net/apidocs/net/sf/json/package-summary.html)。 此外,我使用规格BDD框架(http://code.google.com/p/specs/)进行单元测试。在doBefore块中,我有以下代码:在scala中对JSON数组进行迭代
doBefore {
iter = serversJSON.iterator()
}
serversJSON是一个JSONArray对象。在doBefore块之外,我已经声明了如下变量:
var serversJSON:JSONArray = null
var iter:Iterator[JSONArray] = null
但是在编译时出现以下错误。
error: type mismatch; found : java.util.Iterator[?0] where type ?0 required: java.util.Iterator[net.sf.json.JSONArray] iter = serversJSON.iterator()
我想我在外面声明iter对象的方式doBefore是不正确的。如何解决这个问题?请致电 谢谢。