我在我的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是不正確的。如何解決這個問題?請致電 謝謝。