Example usage for org.json.simple JSONArray get

List of usage examples for org.json.simple JSONArray get

Introduction

In this page you can find the example usage for org.json.simple JSONArray get.

Prototype

public E get(int index) 

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:gov.nasa.jpl.xdata.nba.impoexpo.parse.ParseUtil.java

public static GameSummary parseGameSummary(JSONObject jsonObject) {
    JSONArray resultSets = (JSONArray) jsonObject.get("resultSets");
    JSONObject infoObject = (JSONObject) resultSets.get(0);
    JSONArray rowSet = (JSONArray) infoObject.get("rowSet");
    JSONArray row = (JSONArray) rowSet.get(0);
    String gameSummaryDateEst = (String) row.get(0);
    long gameSummarySequence = (Long) row.get(1);
    long gameSummaryId = Long.parseLong(row.get(2).toString().trim());
    long gameStatusId = (Long) row.get(3);
    String gameStatusText = (String) row.get(4);
    String gameCode = (String) row.get(5);
    long homeTeamId = Long.parseLong(row.get(6).toString().trim());
    long visitorTeamId = (Long) row.get(7);
    long season = Long.parseLong(row.get(8).toString().trim());
    long livePeriod = (Long) row.get(9);
    String livePcTimeString = row.get(10).toString();
    long livePcTime = livePcTimeString.isEmpty() ? 0 : Long.parseLong(livePcTimeString);
    String broadcasterAbbrev = (String) row.get(11);
    String livePeriodTimeBcast = (String) row.get(12);
    long whStatus = (Long) row.get(13);

    return GameSummary.newBuilder().setGameSummaryDateEst(gameSummaryDateEst)
            .setGameSummarySequence(gameSummarySequence).setGameGameSummaryId(gameSummaryId)
            .setGameStatusId(gameStatusId).setGameStatusText(gameStatusText).setGameCode(gameCode)
            .setGameSummaryHomeTeamId(homeTeamId).setGameSummaryVisitorTeamId(visitorTeamId).setSeason(season)
            .setLivePeriod(livePeriod).setLivePcTime(livePcTime)
            .setNatlTvBroadcasterAbbreviation(broadcasterAbbrev).setLivePeriodTimeBcast(livePeriodTimeBcast)
            .setWhStatus(whStatus).build();
}

From source file:gov.nasa.jpl.xdata.nba.impoexpo.parse.ParseUtil.java

public static List<InactivePlayers> parseInactivePlayers(JSONObject jsonObject) {
    JSONArray resultSets = (JSONArray) jsonObject.get("resultSets");
    JSONObject inactivePlayersObject = (JSONObject) resultSets.get(9);
    JSONArray rowSet = (JSONArray) inactivePlayersObject.get("rowSet");
    List<InactivePlayers> result = new ArrayList<InactivePlayers>();
    for (Object rowObject : rowSet) {
        JSONArray row = (JSONArray) rowObject;
        result.add(InactivePlayers.newBuilder()
                .setInactivePlayersPlayerId(row.get(0) == null ? -1 : (Long) row.get(0))
                .setInactivePlayersFirstName(row.get(1) == null ? "" : (String) row.get(1))
                .setInactivePlayersLastName(row.get(2) == null ? "" : (String) row.get(2))
                .setInactivePlayersJerseyNum(
                        row.get(3) == null ? -1 : Long.parseLong(row.get(3).toString().trim()))
                .setInactivePlayersTeamId(row.get(4) == null ? -1 : (Long) row.get(4))
                .setInactivePLayersTeamCity(row.get(5) == null ? "" : (String) row.get(5))
                .setInactivePlayersTeamName(row.get(6) == null ? "" : (String) row.get(6))
                .setInactivePlayersTeamAbbreviation(row.get(7) == null ? "" : (String) row.get(7)).build());
    }/* w  ww .ja v  a  2  s . c o  m*/
    return result;
}

From source file:com.creapple.tms.mobiledriverconsole.utils.MDCUtils.java

/**
 * Get distance information between two GPS
 * @param originLat//from  www. ja  v  a2  s . c om
 * @param originLon
 * @param destLat
 * @param destLon
 * @return
 */
public static String[] getDistanceInfo(double originLat, double originLon, double destLat, double destLon) {

    String[] infos = new String[] { "0", "0" };

    String address = Constants.GOOGLE_DISTANCE_MATRIX_ADDRESS;
    address += originLat + "," + originLon;
    address += "&destinations=";
    address += destLat + "," + destLon;
    address += "&mode=driving&units=metric&language=en&key=";
    address += Constants.GOOGLE_DISTANCE_MATRIX_API_KEY;
    OkHttpClient client = new OkHttpClient();
    Request request = new Request.Builder().url(address).build();
    Response response = null;
    String dist = null;
    try {
        response = client.newCall(request).execute();
        dist = response.body().string();
    } catch (IOException e) {
        return infos;
    }

    Log.d("@@@@@@", dist);
    JSONParser jsonParser = new JSONParser();
    JSONObject jsonObject = null;
    try {
        jsonObject = (JSONObject) jsonParser.parse(dist);
    } catch (ParseException e) {
        return infos;
    }

    // status check as well

    JSONArray rows = (JSONArray) jsonObject.get(Constants.GOOGLE_DISTANCE_MATRIX_ROWS);
    for (int i = 0; i < rows.size(); i++) {
        JSONObject obj = (JSONObject) rows.get(i);
        JSONArray elements = (JSONArray) obj.get(Constants.GOOGLE_DISTANCE_MATRIX_ELEMENTS);
        for (int j = 0; j < elements.size(); j++) {
            JSONObject datas = (JSONObject) elements.get(j);
            JSONObject distance = (JSONObject) datas.get(Constants.GOOGLE_DISTANCE_MATRIX_DISTANCE);
            JSONObject duration = (JSONObject) datas.get(Constants.GOOGLE_DISTANCE_MATRIX_DURATION);
            infos[0] = distance.get(Constants.GOOGLE_DISTANCE_MATRIX_VALUE) + "";
            infos[1] = duration.get(Constants.GOOGLE_DISTANCE_MATRIX_TEXT) + "";

        }

    }
    String status = jsonObject.get(Constants.GOOGLE_DISTANCE_MATRIX_STATUS).toString();
    //        Log.d("@@@@@@", status);
    if (!StringUtils.equalsIgnoreCase(Constants.GOOGLE_DISTANCE_MATRIX_OK, status)) {
        return infos;
    }
    return infos;
}

From source file:gov.nasa.jpl.xdata.nba.impoexpo.parse.ParseUtil.java

public static List<TeamStats> parseTeamStats(JSONObject jsonObject) {
    JSONArray resultSets = (JSONArray) jsonObject.get("resultSets");
    JSONObject infoObject = (JSONObject) resultSets.get(5);
    JSONArray rowSet = (JSONArray) infoObject.get("rowSet");
    List<TeamStats> result = new ArrayList<TeamStats>();
    for (Object rowObject : rowSet) {
        JSONArray row = (JSONArray) rowObject;
        result.add(TeamStats.newBuilder()
                .setGameTeamStatsId(row.get(0) == null ? -1 : Long.parseLong((String) row.get(0)))
                .setTeamStatsTeamId(row.get(1) == null ? -1 : (Long) row.get(1))
                .setTeamStatsTeamName(row.get(2) == null ? "" : (String) row.get(2))
                .setTeamStatsTeamAbbreviation(row.get(3) == null ? "" : (String) row.get(3))
                .setTeamStatsTeamCity(row.get(4) == null ? "" : (String) row.get(4))
                .setTeamStatsMin(row.get(5) == null ? "" : (String) row.get(5))
                .setTeamStatsFgm(row.get(6) == null ? -1 : (Long) row.get(6))
                .setTeamStatsFga(row.get(7) == null ? -1 : (Long) row.get(7))
                .setTeamStatsfgPct(row.get(8) == null ? -1
                        : Math.round((Double.parseDouble(row.get(8).toString().trim())) * 100))
                .setTeamStatsfg3m(row.get(9) == null ? -1 : (Long) row.get(9))
                .setTeamStatsfg3a(row.get(10) == null ? -1 : (Long) row.get(10))
                .setTeamStatsfg3Pct(row.get(11) == null ? -1
                        : Math.round((Double.parseDouble(row.get(11).toString().trim())) * 100))
                .setTeamStatsftm(row.get(12) == null ? -1 : (Long) row.get(12))
                .setTeamStatsfta(row.get(13) == null ? -1 : (Long) row.get(13))
                .setTeamStatsftPct(row.get(14) == null ? -1
                        : Math.round((Double.parseDouble(row.get(14).toString().trim())) * 100))
                .setTeamStatsoreb(row.get(15) == null ? -1 : (Long) row.get(15))
                .setTeamStatsdreb(row.get(16) == null ? -1 : (Long) row.get(16))
                .setTeamStatsreb(row.get(17) == null ? -1 : (Long) row.get(17))
                .setTeamStatsast(row.get(18) == null ? -1 : (Long) row.get(18))
                .setTeamStatsstl(row.get(19) == null ? -1 : (Long) row.get(19))
                .setTeamStatsblk(row.get(20) == null ? -1 : (Long) row.get(20))
                .setTeamStatsto(row.get(21) == null ? -1 : (Long) row.get(21))
                .setTeamStatspf(row.get(22) == null ? -1 : (Long) row.get(22))
                .setTeamStatsPts(row.get(23) == null ? -1 : (Long) row.get(23))
                .setTeamStatsPlusMinus(row.get(24) == null ? -1 : (Long) row.get(24)).build());
    }//from w  w w  . j a  va 2s.  c o m
    return result;
}

From source file:gov.nasa.jpl.xdata.nba.impoexpo.parse.ParseUtil.java

public static List<PlayerStats> parsePlayerStats(JSONObject jsonObject) {
    JSONArray resultSets = (JSONArray) jsonObject.get("resultSets");
    JSONObject infoObject = (JSONObject) resultSets.get(4);
    JSONArray rowSet = (JSONArray) infoObject.get("rowSet");
    List<PlayerStats> result = new ArrayList<PlayerStats>();
    for (Object rowObject : rowSet) {
        JSONArray row = (JSONArray) rowObject;
        result.add(PlayerStats.newBuilder()
                .setGamePlayerStatsId(row.get(0) == null ? -1 : Long.parseLong((String) row.get(0)))
                .setPlayerStatsTeamId(row.get(1) == null ? -1 : (Long) row.get(1))
                .setPlayerStatsTeamAbbreviation(row.get(2) == null ? "" : (String) row.get(2))
                .setPlayerStatsTeamCity(row.get(3) == null ? "" : (String) row.get(3))
                .setPlayerStatsPlayerId(row.get(4) == null ? -1 : (Long) row.get(4))
                .setPlayerName(row.get(5) == null ? "" : (String) row.get(5))
                .setStartPosition(row.get(6) == null ? "" : (String) row.get(6))
                .setComment(row.get(7) == null ? "" : (String) row.get(7))
                .setPlayerStatsMin(row.get(8) == null ? "" : (String) row.get(8))
                .setPlayerStatsFgm(row.get(9) == null ? -1 : (Long) row.get(9))
                .setPlayerStatsFga(row.get(10) == null ? -1 : (Long) row.get(10))
                .setPlayerStatsfgPct(row.get(11) == null ? -1
                        : Math.round((Double.parseDouble(row.get(11).toString().trim())) * 100))
                .setPlayerStatsfg3m(row.get(12) == null ? -1 : (Long) row.get(12))
                .setPlayerStatsfg3a(row.get(13) == null ? -1 : (Long) row.get(13))
                .setPlayerStatsfg3Pct(row.get(14) == null ? -1
                        : Math.round((Double.parseDouble(row.get(14).toString().trim())) * 100))
                .setPlayerStatsftm(row.get(15) == null ? -1 : (Long) row.get(15))
                .setPlayerStatsfta(row.get(16) == null ? -1 : (Long) row.get(16))
                .setPlayerStatsftPct(row.get(17) == null ? -1
                        : Math.round((Double.parseDouble(row.get(17).toString().trim())) * 100))
                .setPlayerStatsoreb(row.get(18) == null ? -1 : (Long) row.get(18))
                .setPlayerStatsdreb(row.get(19) == null ? -1 : (Long) row.get(19))
                .setPlayerStatsreb(row.get(20) == null ? -1 : (Long) row.get(20))
                .setPlayerStatsast(row.get(21) == null ? -1 : (Long) row.get(21))
                .setPlayerStatsstl(row.get(22) == null ? -1 : (Long) row.get(22))
                .setPlayerStatsblk(row.get(23) == null ? -1 : (Long) row.get(23))
                .setPlayerStatsto(row.get(24) == null ? -1 : (Long) row.get(24))
                .setPlayerStatspf(row.get(25) == null ? -1 : (Long) row.get(25))
                .setPlayerStatsPts(row.get(26) == null ? -1 : (Long) row.get(26))
                .setPlayerStatsPlusMinus(row.get(27) == null ? -1 : (Long) row.get(27)).build());
    }//from   ww  w . j a  v  a  2 s .co  m
    return result;
}

From source file:com.github.lgi2p.obirs.utils.JSONConverter.java

/**
 * {"log": "", "annotations" : [{ "text": "uranium", "startpos": 723,
 * "endpos":730, "uris":["http://www.cea.fr/ontotoxnuc#Uranium"] },{ "text":
 * "protein", "startpos": 1837, "endpos":1845,
 * "uris":["http://www.cea.fr/ontotoxnuc#Proteine"] },{ "text": "plant",
 * "startpos": 4661, "endpos":4666,/*w ww.j ava  2 s .c o m*/
 * "uris":["http://www.cea.fr/ontotoxnuc#Plante"] }]}
 *
 * @param jsonQuery
 * @return
 * @throws ParseException
 * @throws Exception
 */
protected static String toJSONindexFormat(int id, String title, String content, String href)
        throws ParseException, Exception {

    URIFactory f = URIFactoryMemory.getSingleton();

    content = content.replace("\n", "").replace("\r", "");
    Object obj = new JSONParser().parse(content);
    JSONObject jsonObject = (JSONObject) obj;
    JSONArray annotations = (JSONArray) jsonObject.get("annotations");

    Set<URI> concepts = new HashSet<URI>();

    if (annotations != null) {
        Iterator<JSONObject> iterator = annotations.iterator();
        while (iterator.hasNext()) {
            JSONObject concept = iterator.next();
            JSONArray uris = (JSONArray) concept.get("uris");
            for (int i = 0; i < uris.size(); i++) {
                concepts.add(f.getURI((String) uris.get(i)));
            }
        }

    }

    String urisAsString = "";
    for (URI u : concepts) {
        if (!urisAsString.isEmpty()) {
            urisAsString += ",";
        }
        urisAsString += "\"" + u.stringValue() + "\"";
    }
    return "{\"id\":\"" + id + "\",\"title\":\"" + title + "\",\"conceptIds\":[" + urisAsString
            + "],\"href\":\"" + href + "\"}";
}

From source file:configuration.Key.java

/**
 * Returns the keys provided in the JSON array.
 * /*ww w.  j a  v a 2s .c o m*/
 * @param array
 *            the JSON array to parse for keys.
 * @return the keys provided in the JSON array.
 */
public static Key[] parseKeys(JSONArray array) {
    List<Key> keys = new LinkedList<Key>();

    if (array == null) {
        throw new NullPointerException("array may not be null!");
    }

    for (int i = 0; i < array.size(); i++) {
        JSONObject object = (JSONObject) array.get(i);
        String key = (String) object.get(KEY_KEY);
        Long version = (Long) object.get(KEY_VERSION);
        int versionInt = version.intValue();
        String algorithm = (String) object.get(KEY_ALGORITHM);
        /*
         * getEncoded() returns the raw bytes of the key (s.
         * http://docs.oracle
         * .com/javase/7/docs/api/javax/crypto/SecretKey.html)
         */
        try {
            byte[] rawKey = Coder.decodeBASE64(key);
            SecretKey secretKey = new SecretKeySpec(rawKey, getSecretKeyAlgorithm(algorithm));
            keys.add(new Key(secretKey, versionInt, algorithm));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    return keys.toArray(new Key[0]);
}

From source file:luceneindexdemo.LuceneIndexDemo.java

public static void searchIndex(String s) throws IOException, ParseException, SQLException,
        FileNotFoundException, org.json.simple.parser.ParseException {

    Directory directory = FSDirectory.getDirectory(INDEX_DIRECTORY);
    IndexReader reader = IndexReader.open(directory);
    IndexSearcher search = new IndexSearcher(reader);
    Analyzer analyzer = new StandardAnalyzer();

    QueryParser queryparser = new QueryParser(FIELD_CONTENTS, analyzer);
    Query query = queryparser.parse(s);
    Hits hits = search.search(query);//from w w w. ja  va  2  s  .  c  o  m
    Iterator<Hit> it = hits.iterator();
    //System.out.println("hits:"+hits.length());
    float f_score;
    List<String> names = new ArrayList<>();
    while (it.hasNext()) {
        Hit hit = it.next();
        f_score = hit.getScore();

        //System.out.println(f_score);
        Document document = hit.getDocument();
        Field f = document.getField(FIELD_PATH);

        //System.out.println(f.readerValue());
        //System.out.println(document.getValues(FIELD_PATH));
        String path = document.get(FIELD_PATH);
        System.out.println(document.getValues(path));
        Field con = document.getField(FIELD_PATH);
        //System.out.println("hit:"+path+" "+hit.getId()+" "+con);
        names.add(new File(path).getName());
    }

    //ProcessBuilder pb=new ProcessBuilder();
    FileReader fReader = new FileReader("/home/rishav12/NetBeansProjects/LuceneIndexDemo/inntell.json");
    JSONParser jsParser = new JSONParser();
    //System.out.println("This is an assumption that you belong to US");
    FileReader freReader = new FileReader("/home/rishav12/NetBeansProjects/LuceneIndexDemo/location.json");
    Connection con = DriverManager.getConnection("jdbc:neo4j://localhost:7474/");
    System.out.println(names);
    if (names.get(0).equals("miss")) {

        System.out.println(s);
        StringTokenizer stringTokenizer = new StringTokenizer(s);
        Connection con1 = DriverManager.getConnection("jdbc:neo4j://localhost:7474/");
        String querySearch = "match ()-[r:KNOWS]-() where has(r.relType) return distinct r.relType";
        ResultSet rSet = con.createStatement().executeQuery(querySearch);
        List<String> allRels = new ArrayList<>();
        while (rSet.next()) {
            System.out.println();
            allRels.add(rSet.getString("r.relType"));
        }
        //System.out.println(rSet);

        while (stringTokenizer.hasMoreTokens()) {
            String next = stringTokenizer.nextToken();
            if (allRels.contains(next)) {
                missOperation(next);
            }
            //System.out.println(resSet.getString("r.relType"));

        }
        System.out.println(names.get(1));
        //missOperation(names.get(1));
    } else {
        try {
            JSONObject jsonObj = (JSONObject) jsParser.parse(fReader);
            System.out.println(names.get(0));

            JSONObject jsObj = (JSONObject) jsonObj.get(names.get(0));
            JSONObject results = new JSONObject();
            System.out.println(jsObj.get("explaination"));
            results.put("explaination", jsObj.get("explaination"));
            JSONArray reqmts = (JSONArray) jsObj.get("true");
            System.out.println("Let me look out for the places that contains ");
            List<String> lis = new ArrayList<>();
            JSONObject locObj = (JSONObject) jsParser.parse(freReader);
            JSONArray jsArray = (JSONArray) locObj.get("CHENNAI");
            Iterator<JSONArray> ite = reqmts.iterator();
            int k = 0;
            String resQuery = "START n=node:restaurant('withinDistance:[" + jsArray.get(0) + ","
                    + jsArray.get(1) + ",7.5]') where";
            Iterator<JSONArray> ite1 = reqmts.iterator();
            while (ite1.hasNext())
                System.out.println(ite1.next());

            while (ite.hasNext()) {
                lis.add("n.type=" + "'" + ite.next() + "'");
                if (k == 0)
                    resQuery += " " + lis.get(k);
                else
                    resQuery += " or " + lis.get(k);
                //System.out.println(attrib);
                k++;

            }
            resQuery += " return n.name,n.place,n.type";
            File writeTo = new File(
                    "/home/rishav12/NetBeansProjects/LuceneIndexDemo/filestoIndex1/" + names.get(0));
            FileOutputStream fop = new FileOutputStream(writeTo, true);
            String writeTOFile = s + "\n";
            fop.write(writeTOFile.getBytes());
            //System.out.println(resQuery);
            ResultSet res = con.createStatement().executeQuery(resQuery);
            JSONArray resSet = new JSONArray();

            while (res.next()) {
                System.out.println(" name:" + res.getString("n.name") + " located:" + res.getString("n.place")
                        + " type:" + res.getString("n.type"));
                JSONObject jsPart = new JSONObject();
                jsPart.put("name", res.getString("n.name"));
                jsPart.put("located", res.getString("n.place"));
                jsPart.put("type", res.getString("n.type"));
                resSet.add(jsPart);
            }
            results.put("results", resSet);
            File resultFile = new File("result.json");
            FileOutputStream fop1 = new FileOutputStream(resultFile);
            System.out.println(results);
            fop1.write(results.toJSONString().getBytes());
            //String resQuery="START n=node:restaurant('withinDistance:[40.7305991, -73.9865812,10.0]') where n.coffee=true return n.name,n.address;";
            //System.out.println("Sir these results are for some coffee shops nearby NEW YORK");
            //ResultSet res=con.createStatement().executeQuery(resQuery);
            //while(res.next())
            //System.out.println("name: "+res.getString("n.name")+" address: "+res.getString("n.address"));
        } catch (org.json.simple.parser.ParseException ex) {
            Logger.getLogger(LuceneIndexDemo.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}

From source file:naftoreiclag.villagefive.util.json.JSONUtil.java

public static <ConcreteJSONThingy extends JSONThingy> List<ConcreteJSONThingy> readList(JSONArray array,
        ConcreteJSONThingy expectedType) {
    List<ConcreteJSONThingy> newList = new ArrayList<ConcreteJSONThingy>();

    for (int i = 0; i < array.size(); ++i) {
        ConcreteJSONThingy thing = null;
        try {//from  www . j a v a2s . c o  m
            //thing = (ConcreteJSONThingy) expectedType.getClass().getMethod("createFromJson", JSONObject.class).invoke(expectedType, array.get(i));
            thing = (ConcreteJSONThingy) expectedType.createFromJson((JSONObject) array.get(i));
            //thing = expectedType.getConstructor(JSONObject.class).newInstance(array.get(i));
        } catch (Exception ex) {
            Logger.getLogger(JSONThingy.class.getName()).log(Level.SEVERE, null, ex);
        }

        newList.add(thing);

    }

    return newList;
}

From source file:com.netbase.insightapi.bestpractice.TopicDownloader.java

/**
 * Gets the earliest timestamp that would match the query. Returns
 * Integer.MAX_VALUE if the query matches no documents.
 * //from  w  ww .  j  av a 2s .  c  o m
 * @param masterQuery
 * @param user
 * @return
 * @throws InsightAPIQueryException
 * @throws InterruptedException
 */
public static int getEarliestTimestamp(InsightAPIQuery masterQuery, UserChannel user)
        throws InsightAPIQueryException, InterruptedException {
    InsightAPIQuery query = new InsightAPIQuery(masterQuery);
    query.setOp("retrieveDocuments");
    query.setParameter("sort", "timestamp");
    query.setParameter("sizeNeeded", 1);
    user.run(query);
    JSONArray docs = (JSONArray) ((JSONObject) query.getParsedContent()).get("documents");
    if (docs == null || docs.size() == 0)
        return (Integer.MAX_VALUE);
    JSONObject doc = (JSONObject) docs.get(0);
    return (getDocTimestamp(doc));
}