Good day. I want to parse this json file.
The code itself for this case:
import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import org.apache.http.ParseException; import org.json.JSONObject; import java.io.BufferedReader; import java.io.FileReader; public class JSONtest { public static void main(String args[]) throws Exception { JSONtest jsonTest = new JSONtest(); Object ads[] = jsonTest.getAd(); Integer noneAds = 0; for (int i = 1; i <ads.length; i++) { if (ads[i].equals(noneAds)) { System.out.println("Bingo"); } } } public Object[] getAd() throws Exception { BufferedReader bufferedReader = new BufferedReader(new FileReader("C:/TAP/src/main/resources/vk.json")); JsonParser parser = new JsonParser(); Object [] ads = new Object[7]; try { JsonObject jsonResp = (JsonObject) parser.parse(bufferedReader); JsonArray postsList = (JsonArray) jsonResp.get("response"); JsonObject unicPost = null; JSONObject jsonObject; for (int i = 1; i < postsList.size(); i++) { unicPost = (JsonObject) postsList.get(i); ads[i] = unicPost.get("marked_as_ads"); System.out.println("Ads from sub " + ads[i]); } } catch (ParseException e) {e.printStackTrace();} return ads; } } In main'e I want to compare the data obtained from the getAds method with the value 0 of type Integer, but since they are of a different type, the result is false, where true should be; I tried to build, but the ClassCastException always crashed. What can be done?
