Example usage for org.json JSONObject append

List of usage examples for org.json JSONObject append

Introduction

In this page you can find the example usage for org.json JSONObject append.

Prototype

public JSONObject append(String key, Object value) throws JSONException 

Source Link

Document

Append values to the array under a key.

Usage

From source file:org.wso2.carbon.connector.integration.test.gplus.GooglePlusTestCase.java

/**
 * Optional parameter test case for listByActivity method with maxResults,fields Optional Parameters.
 *//*  w  ww.  j ava  2 s  .  c o m*/
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testListByActivityWithMandatoryParams" }, description = "GooglePlus {listByActivity} integration test with mandatory and maxResults,fields optional parameters.")
public void testListByActivityWithTwoOptionalParam3() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "listByActivityOptionalParams.txt";
    String methodName = "listByActivity";
    final String requestJsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml";
    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));
    JSONObject jsonObject = new JSONObject(requestJsonString);
    jsonObject.append("activityId", googlePlusConnectorProperties.getProperty("activityId"));
    jsonObject.append("pageToken", googlePlusConnectorProperties.getProperty("listByActivityPageToken"));
    jsonObject.append("apiUrl", googlePlusConnectorProperties.getProperty("apiUrl"));
    jsonObject.append("clientId", googlePlusConnectorProperties.getProperty("clientId"));
    jsonObject.append("clientSecret", googlePlusConnectorProperties.getProperty("clientSecret"));
    jsonObject.append("refreshToken", googlePlusConnectorProperties.getProperty("refreshToken"));
    String modifiedJsonString = jsonObject.toString().replace("[", "").replace("]", "");
    try {
        String[] unneededOptionalParameters = { "pageToken" };
        String requiredJsonString = ConnectorIntegrationUtil.getRequiredJsonString(modifiedJsonString,
                unneededOptionalParameters);
        JSONObject responseJson = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName),
                requiredJsonString);
        junit.framework.Assert.assertEquals("plus#peopleFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

From source file:org.wso2.carbon.connector.integration.test.gplus.GooglePlusTestCase.java

/**
 * Negative parameter test case for listPeople method.
 *///from ww w  .  j a va2  s  . c o m
@Test(groups = {
        "wso2.esb" }, description = "GooglePlus {listByActivity} integration test with Negative parameters.")
public void testListByActivityWithNegativeParams() throws Exception {

    String jsonRequestFilePath = pathToRequestsDirectory + "listByActivityUnhappy.txt";
    String methodName = "listByActivity";
    final String requestJsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml";
    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));
    JSONObject jsonObject = new JSONObject(requestJsonString);
    jsonObject.append("apiUrl", googlePlusConnectorProperties.getProperty("apiUrl"));
    jsonObject.append("clientId", googlePlusConnectorProperties.getProperty("clientId"));
    jsonObject.append("clientSecret", googlePlusConnectorProperties.getProperty("clientSecret"));
    jsonObject.append("refreshToken", googlePlusConnectorProperties.getProperty("refreshToken"));
    String modifiedJsonString = jsonObject.toString().replace("[", "").replace("]", "");
    try {

        int statusCode = ConnectorIntegrationUtil.sendRequestToRetrieveHeaders(getProxyServiceURL(methodName),
                modifiedJsonString);
        junit.framework.Assert.assertTrue(statusCode == 400 || statusCode == 400);
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

From source file:biblivre3.z3950.Z3950SearchResultDTO.java

@Override
public JSONObject toJSONObject(Properties properties) {
    JSONObject json = new JSONObject();

    try {/* ww w.  j  a  v a 2 s.c  o  m*/
        json.put("totalPages", this.totalPages);
        json.put("totalRecords", this.totalRecords);
        json.put("currentPage", this.currentPage);
        json.put("recordsPerPage", this.recordsPerPage);

        for (Z3950ResultRow rr : this.al) {
            json.append("results", rr.toJSONObject(null));
        }
    } catch (JSONException e) {
    }

    return json;
}

From source file:biblivre3.administration.cards.CardSearchResultsDTO.java

@Override
public JSONObject toJSONObject(Properties properties) {
    JSONObject json = new JSONObject();
    try {/*from   w  ww .j  a  va2  s .c om*/
        json.put("totalPages", this.totalPages);
        json.put("totalRecords", this.totalRecords);
        json.put("currentPage", this.currentPage);
        json.put("recordsPerPage", this.recordsPerPage);

        for (DTO rr : this.al) {
            json.append("results", rr.toJSONObject(null));
        }
    } catch (JSONException e) {
    }

    return json;
}

From source file:org.cosmo.common.util.Util.java

public String JSON(Object... args) {
    try {/*  w  ww.  j  a  v  a2  s  . c o  m*/
        JSONObject json = new JSONObject();
        for (int i = 0; i < args.length; i = i + 2) {
            json.append(args[i].toString(), args[i + 1]);
        }
        return json.toString();
    } catch (JSONException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:subsets.GenerateGFKMatrix.java

public void part_tree(TreeMap<String, HashSet> treemap_hashset,
        TreeMap<String, JSONObject> treemap_previous_jsonobject,
        TreeMap<String, JSONObject> treemap_next_jsonobject, boolean atbottom) {
    try {/* w ww . jav a 2  s . c o  m*/

        for (String head : treemap_hashset.keySet()) {
            JSONObject json_head = new JSONObject();

            json_head.append("name", head.toString());

            HashSet hashset = treemap_hashset.get(head);
            Iterator it = hashset.iterator();

            while (it.hasNext()) {
                String leave = (String) it.next();
                JSONObject json_leave = new JSONObject();
                if (atbottom) {
                    json_leave.append("name", leave);
                    json_head.append("children", json_leave);
                } else {

                    JSONObject jsononject_leave = treemap_previous_jsonobject.get(leave);
                    if (jsononject_leave != null) {
                        json_head.append("children", jsononject_leave);
                    } else {
                        JSONObject dummy = new JSONObject();
                        dummy.append("name", leave);
                        json_head.append("children", dummy);
                    }
                }
            }
            treemap_next_jsonobject.put(head, json_head);
        }

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

From source file:subsets.GenerateGFKMatrix.java

void query3() {
    ArrayList<String[]> hirarchy = new ArrayList<String[]>();
    String[] mc = { "sc", "MetaCube" };
    hirarchy.add(mc);// w  w  w.j  a v a 2  s  .  c o m
    String[] sc = { "sc", "name" };
    hirarchy.add(sc);
    String[] sca = { "sca", "name" };
    hirarchy.add(sca);
    String[] bca = { "bca", "name" };
    hirarchy.add(sca);

    TreeMap<String, JSONObject> SmartCube_SCAttribut = getDepTree(
            "MATCH (sc:SmartCube)<-[:MEMBER_OF]-(sca:SCAttribut) RETURN sc,sca", hirarchy);

    hirarchy.clear();

    //ArrayList<String[]> hirarchy = new ArrayList<String[]>();

    hirarchy.add(sc);
    hirarchy.add(sca);
    hirarchy.add(bca);
    TreeMap<String, JSONObject> SCAttribut_SCAlgo_BCAttribut = getDepTree_old(
            "MATCH (sc:SCAttribut) -[:DERIVED_BY]->(sca:SCAlgorithmen)-[:USES] ->(bca:BCAttribut) RETURN sc,sca,bca",
            hirarchy);

    hirarchy.clear();
    hirarchy.add(sc);
    hirarchy.add(bca);
    TreeMap<String, JSONObject> SCAttribut_BCAttribut = getDepTree(
            "MATCH (sc:SCAttribut) -[:TRANSITION]->(bca:BCAttribut) RETURN sc,bca", hirarchy);

    JSONObject MetaCube = new JSONObject();
    try {
        MetaCube.append("name", "MetaCube");

        for (String key : SmartCube_SCAttribut.keySet()) {
            JSONObject cube = SmartCube_SCAttribut.get(key);
            MetaCube.append("children", cube);
        }

    } catch (JSONException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    String content = MetaCube.toString();

    try {

        //String content = json_smartcube.toString();

        File file = new File("C://Users//frisch//Desktop//d3//flare.json");

        // if file doesnt exists, then create it
        if (!file.exists()) {
            file.createNewFile();
        }

        FileWriter fw = new FileWriter(file.getAbsoluteFile());
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(content);
        bw.close();

        System.out.println("Done");

    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:com.facebook.config.TestExpandedConfFileJSONProvider.java

private JSONObject addInclude(JSONObject json, String include) throws JSONException {
    return json.append("includes", include);
}

From source file:$.ExampleResource.java

/**
     * Gets the pages associated to the current site.
     * //from   w w w . j a  v a  2  s  .co m
     * @return List of pages associated to the current site. Empty array if no pages found.
     * @throws JSONException
     */
    @GET
    @Path("pages")
    public JSONObject getPages() throws JSONException {
        JSONObject json = new JSONObject();
        List<SitePage> pages = exampleLogic.getPages();
        if (pages.size() > 0) {
            for (SitePage page : pages) {
                json.append("pages", page.getTitle());
            }
        } else {
            json.put("pages", new JSONArray());
        }
        return json;
    }

From source file:com.webpagebytes.cms.engine.JSONToFromObjectConverter.java

public String JSONStringFromObject(Object object, Map<String, String> additionalData) {
    org.json.JSONObject json = JSONFromObject(object);
    if (additionalData != null) {
        try {//from w  ww .  j av a 2s.  c  o m
            for (String key : additionalData.keySet()) {
                json.append(key, additionalData.get(key));
            }
        } catch (org.json.JSONException e) {
            // TDB
        }
    }
    return json.toString();
}