Iterating over a JSON array in scala -
i'm using json lib net.sf.json(http://json-lib.sourceforge.net/apidocs/net/sf/json/package-summary.html) in scala code. also, i'm using specs bdd framework (http://code.google.com/p/specs/) unit testing. in dobefore block, have following code:
dobefore { iter = serversjson.iterator() }
serversjson jsonarray object. outside dobefore block, have declared variables used follows
var serversjson:jsonarray = null var iter:iterator[jsonarray] = null
but on compilation i'm getting following error.
error: type mismatch; found : java.util.iterator[?0] type ?0 required: java.util.iterator[net.sf.json.jsonarray] iter = serversjson.iterator()
i guess way have declared iter object outside dobefore incorrect. how fix this?
please thank you.
as indicated here, json library's iterator
method returns raw iterator
, not iterator[jsonarray]
. you'll want declare follows:
var serversjson:jsonarray = null var iter:iterator[_] = null
Comments
Post a Comment