开发者

Iterating over a JSON array in scala

I'm using the JSON lib net.sf.json(http://json-lib.sourceforge.net/apidocs/net/sf/json/package-summary.html) in my scala code. Also, I'm using the specs BDD framework (http://code.google.com/p/specs/) for unit testing. In the doBefore block, i have the following code:

doBefore {
  iter = serversJSON.iterator()
}

serversJSON is a JSONArray object. Outside the doBefore block, I have declared the variables used as follows

var serversJSON:JSONArray = null
var iter:Iterator[JSONArray] = null

But on compilation I'm getting the following error.

error: type mismatch; found : java开发者_如何学运维.util.Iterator[?0] where type ?0 required: java.util.Iterator[net.sf.json.JSONArray] iter = serversJSON.iterator()

I guess the way i have declared the iter object outside doBefore is incorrect. How to fix this?

Please Help Thank You.


As indicated here, the JSON library's iterator method returns a raw Iterator, not an Iterator[JSONArray]. You'll want to declare it as follows:

var serversJSON:JSONArray = null
var iter:Iterator[_] = null
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜