Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java -JsonArray.contains(string) no such function?

Tags:

java

json

arrays

I have a JSONArray called playtitles, and a String called playname. I want to iterate through the JSONArray and check for the String, but JSONArray doesn't have a .contains() function, this is the relevant code:

This is the error I get The method contains(String) is undefined for the type JSONArray

I have tried converting playName to a JSON string but that doesn't seem to work either. I have also tried using an ArrayList and then converting it to a JSONArray but that causes more problems.

Any tips?

like image 950
other15 Avatar asked Aug 05 '26 05:08

other15


1 Answers

I think you need to use the following implementation:

http://json-lib.sourceforge.net/

According to their specification, there is a .contains() method for JSONArray.

http://json-lib.sourceforge.net/apidocs/net/sf/json/JSONArray.html#contains(java.lang.Object)

So the import would be something like :

import net.sf.json.JSONArray;
like image 99
panagdu Avatar answered Aug 06 '26 19:08

panagdu