java - Can't add JSONObjects into an array -


i using json simple parse json file. when jsonarray. when try iterate through , jsonobject elements error.

this code:

jsonarray jsondata = (jsonarray) jsonparser.parse(reader);  list<jsonobject> elementslist = new arraylist<jsonobject>();  (int = 1; < jsondata.size(); i++) {      elementslist.addall(jsondata.get(i)); // here jsondata.get(i) jsonobject } 

i following errors in eclipse:

  • the method addall(collection) in type list not applicable arguments (object)
  • type safety: unchecked cast object collection

not sure these mean , how fix that.

jsonarray#get(int) has return type of object (because inherited raw type arraylist). list#addall(collection) expects argument of type collection. type object not convertible collection without type cast.

however, if cast value returned get, underlying value jsonobject , you'd classcastexception @ runtime.

what want

elementslist.addall(jsondata); //  outside loop 

since jsonarray subtype of arraylist collection. you'll warning jsondata requiring unchecked conversion, should assuming have jsonobject values inside jsonarray.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -