Reputation: 1681
Newbie Scala user's here! I was trying to extract all elements in a JSON array one by one, so I was iterating this object. Since Scala doesn't have built-in JSON support, I used a third-party JSON parsing package ujson. I am trying to implement a for-loop on a JSON array like this:
var json = ujson.read("""{"list": ["id":1, "id":2, "id":3]}""")
var index = 0
var iteration: Boolean = true
while(iteration) {
try {
print(json("list")(index))
index += 1
}
catch {
iteration = false
}
}
It encountered a compilation error on the line iteration = false
and said type mismatch;
. So in this question, I am looking for the things listed below:
Scala version: 2.13.12
Upvotes: 0
Views: 100