Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type Safety warning with JSON Iterator

Tags:

java

json

android

My problem comes from getting an Iterator from a JSONObject.

Code generating error in its simplest form:

String json = client.retrieveList(); JSONObject jsonList = new JSONObject(json); Iterator<String> i = jsonList.keys();  while(i.hasNext()) {     String next = i.next();     JSONArray jsonArray = jsonList.getJSONArray(next);     // Do stuff with jsonArray, example: jsonArray.getString(0), jsonArray.getString(1); } 

The exact warning is: Type safety: The expression of type Iterator needs unchecked conversion to conform to Iterator

So the question is how can I eradicate this warning?

Many thanks!

like image 258
Knossos Avatar asked Nov 28 '10 11:11

Knossos


1 Answers

i realize this is an old thread, but for future searchers...

you can also infer a generic and cast the returns of the iterator methods...

Iterator<?> i = jsonList.keys();  while(i.hasNext()) {     String next = (String) i.next();     ... 
like image 80
momo Avatar answered Sep 23 '22 21:09

momo