Example usage for org.json.simple JSONArray toString

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

Introduction

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

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:freebase.api.FreebaseHelper.java

public static JSONArray getJSON(String fromDate, String toDate) {
    try {/*from w  ww .ja va  2s.  com*/
        properties.load(new FileInputStream("freebase.properties"));
        HttpTransport httpTransport = new NetHttpTransport();
        HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
        JSONParser parser = new JSONParser();
        String query = readQueryFromFile("queries/q1.json");
        query = manipulateQuery(query, fromDate, toDate);
        GenericUrl url = new GenericUrl("https://www.googleapis.com/freebase/v1/mqlread");
        url.put("query", query);
        url.put("key", properties.get("API_KEY"));
        System.out.println("URL:" + url);
        HttpRequest request = requestFactory.buildGetRequest(url);
        HttpResponse httpResponse = request.execute();
        JSONObject response = (JSONObject) parser.parse(httpResponse.parseAsString());
        JSONArray results = (JSONArray) response.get("result");
        Utils.writeDataIntoFile(results.toString() + "\n", FreebaseAPI.JSON_DUMP_FILE);

        return results;
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}

From source file:app.NotificationJSONizer.java

public static void jsonize(ArrayList<backend.Notification> notis, PrintWriter out) {
    JSONArray a = new JSONArray();
    notis.stream().forEach((noti) -> {
        JSONObject o = noti.jsonize();//from  w  ww. j  a  v  a2  s .co  m
        o.put("type", noti.get_type().toString());
        a.add(o);
    });

    out.print(a.toString());
}

From source file:at.uni_salzburg.cs.ckgroup.cscpp.mapper.registry.RegistryPersistence.java

@SuppressWarnings("unchecked")
public static void storeRegistry(File registryFile, Map<String, IRegistrationData> registrationData)
        throws IOException {
    synchronized (lock) {
        JSONArray obj = new JSONArray();
        for (Entry<String, IRegistrationData> entry : registrationData.entrySet()) {
            IRegistrationData rd = entry.getValue();
            obj.add(rd);/*from  w ww . ja  v a  2s . c om*/
        }

        PrintWriter pw = new PrintWriter(registryFile);
        pw.print(obj.toString());
        pw.close();
        LOG.info("Registry successfully saved to file " + registryFile);
    }
}

From source file:com.dubture.symfony.core.util.JsonUtils.java

@SuppressWarnings("unchecked")
public static String createDefaultSyntheticServices() {

    JSONArray data = new JSONArray();

    JSONObject request = new JSONObject();
    request.put(Service.NAME, "request");
    request.put(Service.CLASS, "Symfony\\Component\\HttpFoundation\\Request");

    data.add(request);/*from w ww  . j a  v a  2s . co  m*/
    return data.toString();

}

From source file:com.rackspacecloud.blueflood.outputs.handlers.HttpRollupHandlerIntegrationTest.java

public static void testHappyCaseMultiFetchHTTPRequest(List<Locator> locators, String tenantId,
        DefaultHttpClient client) throws Exception {
    HttpPost post = new HttpPost(getBatchMetricsQueryURI(tenantId));
    JSONArray metricsToGet = new JSONArray();
    for (Locator locator : locators) {
        metricsToGet.add(locator.toString());
    }/*from   w  w  w.j  a va  2 s.c o  m*/
    HttpEntity entity = new StringEntity(metricsToGet.toString(), ContentType.APPLICATION_JSON);
    post.setEntity(entity);
    HttpResponse response = client.execute(post);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
}

From source file:at.ait.dme.yuma.suite.apps.core.server.annotation.JSONAnnotationHandler.java

public static ArrayList<Annotation> parseAnnotations(String json) {
    ArrayList<Annotation> annotations = new ArrayList<Annotation>();
    JSONArray jsonArray = (JSONArray) JSONValue.parse(json);

    if (jsonArray == null)
        return annotations;

    for (Object obj : jsonArray) {
        JSONObject jsonObj = (JSONObject) obj;
        Annotation annotation;//from w  ww  .  j  a  va  2s.co  m

        MediaType type = MediaType.valueOf(((String) jsonObj.get(KEY_MEDIA_TYPE)).toUpperCase());
        String fragment = (String) jsonObj.get(KEY_FRAGMENT);
        if (type == MediaType.IMAGE || type == MediaType.MAP) {
            annotation = new ImageAnnotation();

            if ((fragment != null) && (!fragment.isEmpty())) {
                SVGFragmentHandler svg = new SVGFragmentHandler();
                try {
                    annotation.setFragment(svg.toImageFragment((String) jsonObj.get(KEY_FRAGMENT)));
                } catch (IOException e) {
                    logger.warn("Could not parse image fragment: " + e.getMessage());
                }
            }
        } else if (type == MediaType.AUDIO) {
            annotation = new AudioAnnotation();

            if ((fragment != null) && (!fragment.isEmpty())) {
                AudioFragmentHandler afh = new AudioFragmentHandler();
                annotation.setFragment(afh.parseAudioFramgent(fragment));
            }

        } else {
            throw new RuntimeException("Unsupported annotation type: " + type.name());
        }

        annotation.setId((String) jsonObj.get(KEY_ID));
        annotation.setParentId((String) jsonObj.get(KEY_PARENT_ID));
        annotation.setRootId((String) jsonObj.get(KEY_ROOT_ID));
        annotation.setObjectUri((String) jsonObj.get(KEY_OBJECT_URI));
        annotation.setCreated(new Date((Long) jsonObj.get(KEY_CREATED)));
        annotation.setLastModified(new Date((Long) jsonObj.get(KEY_LAST_MODIFIED)));
        annotation.setCreatedBy(parseUser((JSONObject) jsonObj.get(KEY_CREATED_BY)));
        annotation.setTitle((String) jsonObj.get(KEY_TITLE));
        annotation.setText((String) jsonObj.get(KEY_TEXT));
        annotation.setMediaType(type);

        String scope = (String) jsonObj.get(KEY_SCOPE);
        if (scope != null) {
            annotation.setScope(Scope.valueOf(scope.toUpperCase()));
        } else {
            annotation.setScope(Scope.PUBLIC);
        }

        JSONArray jsonTags = (JSONArray) jsonObj.get(KEY_TAGS);
        if (jsonTags != null)
            annotation.setTags(parseSemanticTags(jsonTags));

        JSONArray jsonReplies = (JSONArray) jsonObj.get(KEY_REPLIES);
        if (jsonReplies != null) {
            ArrayList<Annotation> replies = parseAnnotations(jsonReplies.toString());
            annotation.setReplies(replies);
        }

        annotations.add(annotation);
    }
    return annotations;
}

From source file:gov.nih.nci.rembrandt.web.ajax.DynamicListHelper.java

public static String getPathwayGeneSymbols(String pathwayName) {
    List<String> geneSymbols = LookupManager.getPathwayGeneSymbols(pathwayName);
    JSONArray symbols = new JSONArray();
    for (String symbol : geneSymbols) {
        symbols.add(symbol);//ww w .j av a 2s  . com
    }

    return "(" + symbols.toString() + ")";
}

From source file:gov.nih.nci.rembrandt.web.ajax.DynamicListHelper.java

public static String getRBTFeatures() {
    String jfeats = "";
    //get the features from the external props
    String feats = System.getProperty("rembrandt.feedback.features");
    List<String> f = Arrays.asList(feats.split(","));
    JSONArray fs = new JSONArray();
    for (String s : f) {
        s = s.trim();/*from w  ww .  j  av  a2 s.c om*/
        fs.add(s);
    }
    if (fs.size() > 0) {
        jfeats = fs.toString();
    }
    return jfeats;
}

From source file:cloudclient.Client.java

@SuppressWarnings("unchecked")
public static void batchSendTask(PrintWriter out, String workload)
        throws FileNotFoundException, MalformedURLException {

    FileInputStream input = new FileInputStream(workload);
    BufferedReader bin = new BufferedReader(new InputStreamReader(input));

    // Get task from workload file 
    String line;//ww w .  ja va2  s  .  c  o  m
    //       String sleepLength;
    String id;
    int count = 0;
    final int batchSize = 10;

    try {
        //Get client public IP
        String ip = getIP();
        //System.out.println(ip);

        //JSON object Array      
        JSONArray taskList = new JSONArray();

        while ((line = bin.readLine()) != null) {
            //sleepLength = line.replaceAll("[^0-9]", "");
            //System.out.println(sleepLength);
            count++;
            id = ip + ":" + count;

            JSONObject task = new JSONObject();
            task.put("task_id", id);
            task.put("task", line);

            taskList.add(task);

            if (taskList.size() == batchSize) {
                out.println(taskList.toString());
                taskList.clear();
            }
        }

        //System.out.println(taskList.toString());         
        if (!taskList.isEmpty()) {
            out.println(taskList.toString());
            taskList.clear();
        }

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:freebase.api.FreebaseAPIMusic.java

public static List<Recording> getRecording(String fromDate, String toDate) {
    try {/*w  w  w  . j  a  va  2s  .co  m*/
        properties.load(new FileInputStream("freebase.properties"));
        HttpTransport httpTransport = new NetHttpTransport();
        HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
        JSONParser parser = new JSONParser();
        //            String query = "[{\"id\":null,\"name\":null,\"type\":\"/astronomy/planet\"}]";
        String query = readQueryFromFile("queries/q2.json");
        query = manipulateQuery(query, fromDate, toDate);
        //JSONArray queryJObj = (JSONArray) JSONValue.parse(query);
        //query = queryJObj.toJSONString();
        //query = "[{\"id\":null,\"name\":null,\"type\":\"/film/film\"}]";
        //query = "[{\"mid\":null,\"name\":null,\"language\":\"English Language\",\"country\":\"United States of America\",\"type\":\"/film/film\",\"initial_release_date>=\":\"2000-01-01\",\"initial_release_date<=\":\"2020-01-01\",\"initial_release_date\":null,\"directed_by\":[{\"mid\":null,\"name\":null}],\"starring\":[{\"mid\":null,\"actor\":[{\"mid\":null,\"name\":null}],\"character\":[{\"mid\":null,\"name\":null}]}],\"limit\":1}]";
        GenericUrl url = new GenericUrl("https://www.googleapis.com/freebase/v1/mqlread");
        url.put("query", query);
        url.put("key", properties.get("API_KEY"));
        // url.put("cursor", current_cursor);
        System.out.println("URL:" + url);
        HttpRequest request = requestFactory.buildGetRequest(url);
        HttpResponse httpResponse = request.execute();
        JSONObject response = (JSONObject) parser.parse(httpResponse.parseAsString());
        JSONArray results = (JSONArray) response.get("result");
        //            if (response.get("cursor") instanceof Boolean) {
        //                System.out.println("End of The Result, cursor=" + response.get("cursor"));
        //            } else {
        //                current_cursor = (String) response.get("cursor");
        //            }
        //            System.out.println(results.toString());
        Utils.writeDataIntoFile(results.toString() + "\n", JSON_DUMP_FILE);
        List<Recording> recordings = encodeJSON(results);
        return recordings;
        //            for (Object result : results) {
        //                System.out.println(JsonPath.read(result, "$.name").toString());
        //            }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}