How to parse a two dimensional JSON array in java -
this json data
{ "tag1":["haaai ","hello"], "tag2":[["haai1","haai2"],["hello1","hello2","hello3"]] }
i can read array tag1
using java code
jsonarray msg = (jsonarray) jsonobject.get("tag1"); iterator<string> iterator = msg.iterator(); while (iterator.hasnext()) { string text = iterator.next(); system.out.println(text); }
but, can't read tag2
array using above method. idea?
you can't read using same method because format different. have use 2 loops instead.
jsonarray msg = (jsonarray) jsonobject.get("tag2"); iterator<jsonarray> iterator = msg.iterator(); while (iterator.hasnext()) { iterator<string> inneriterator = iterator.next().iterator(); while (inneriterator.hasnext()) { string text = inneriterator.next(); system.out.println(text); } }
Comments
Post a Comment