Example usage for org.json JSONObject put

List of usage examples for org.json JSONObject put

Introduction

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

Prototype

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

Source Link

Document

Put a key/value pair in the JSONObject.

Usage

From source file:CNCEntities.ResponseRequest.java

@Override
public JSONObject getJsonEntity() {
    JSONObject jo = new JSONObject();
    try {// w w  w  .  j  a v a  2  s. com
        jo.put("msg", msg);
        jo.put("tranid", tranid);
        jo.put("code", code);
        jo.put("listCards", listCards);
    } catch (JSONException ex) {
        Logger.getLogger(ResponseRequest.class.getName()).log(Level.SEVERE, null, ex);
    }
    return jo;
}

From source file:com.google.appengine.tools.mapreduce.ConfigurationTemplatePreprocessor.java

/**
 * Generate a JSON version of the template described by this object named
 * by the given {@code name}./*from  w w  w.j a va  2s . co m*/
 */
public JSONObject toJson(String name) {
    JSONObject propertiesMap = new JSONObject();
    Map<String, TemplateEntryMetadata> metadataMap = getMetadataMap();
    for (Entry<String, TemplateEntryMetadata> entry : metadataMap.entrySet()) {
        convertPropertiesToJson(propertiesMap, entry);
    }

    JSONObject configObject = new JSONObject();
    try {
        configObject.put("name", name);
        configObject.put("mapper_params", propertiesMap);
    } catch (JSONException e) {
        throw new RuntimeException("Hard-coded string is null", e);
    }
    return configObject;
}

From source file:com.google.appengine.tools.mapreduce.ConfigurationTemplatePreprocessor.java

private void convertPropertiesToJson(JSONObject propertiesMap, Entry<String, TemplateEntryMetadata> entry) {
    JSONObject configObject = new JSONObject();
    try {//from  w  w  w .j  a  va  2  s.c  o  m
        configObject.put("human_name", entry.getValue().getHumanName());
        configObject.put("default_value", entry.getValue().getDefaultValue());
    } catch (JSONException e) {
        throw new RuntimeException("Apparently, a string is now null.", e);
    }
    try {
        propertiesMap.put(entry.getKey(), configObject);
    } catch (JSONException e) {
        throw new RuntimeException("Got a null property key");
    }
}

From source file:com.swiftnav.sbp.tracking.TrackingChannelStateDepA.java

@Override
public JSONObject toJSON() {
    JSONObject obj = new JSONObject();
    obj.put("state", state);
    obj.put("prn", prn);
    obj.put("cn0", cn0);
    return obj;/*from   www  .j  a  v a  2 s.c o  m*/
}

From source file:edu.umass.cs.protocoltask.examples.PingPongPacket.java

@Override
public JSONObject toJSONObjectImpl() throws JSONException {
    JSONObject json = new JSONObject();
    json.put(FIELD1, this.field1);
    json.put(COUNTER, this.counter);
    return json;//from ww  w  .ja va  2 s . c  om
}

From source file:com.citrus.sdk.payment.PaymentBill.java

public static JSONObject toJSONObject(PaymentBill paymentBill) {
    JSONObject billObject = null;

    if (paymentBill != null) {
        Amount amount = paymentBill.getAmount();
        String merchantAccessKey = paymentBill.getMerchantAccessKey();
        String merchantTransactionId = paymentBill.getMerchantTransactionId();
        String requestSignature = paymentBill.getRequestSignature();
        String returnUrl = paymentBill.getReturnUrl();
        String notifyUrl = paymentBill.getNotifyUrl();
        Map<String, String> customParametersMap = paymentBill.getCustomParametersMap();

        if (amount != null && requestSignature != null && merchantAccessKey != null
                && merchantTransactionId != null && returnUrl != null) {

            try {
                billObject = new JSONObject();
                billObject.put("amount", Amount.toJSONObject(amount));
                billObject.put("merchantTxnId", merchantTransactionId);
                billObject.put("merchantAccessKey", merchantAccessKey);
                billObject.put("requestSignature", requestSignature);
                billObject.put("returnUrl", returnUrl);

                if (!TextUtils.isEmpty(notifyUrl)) {
                    billObject.put("notifyUrl", notifyUrl);
                }/* ww w . j  a  va2 s  .  c  om*/

                // Putting customParameters
                if (customParametersMap != null && customParametersMap.size() > 0) {
                    JSONObject customParamsObj = new JSONObject();
                    for (Map.Entry<String, String> entry : customParametersMap.entrySet()) {
                        customParamsObj.put(entry.getKey(), entry.getValue());
                    }

                    billObject.put("customParameters", customParamsObj);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }

    return billObject;
}

From source file:org.wso2.carbon.connector.clevertim.UpdateCase.java

/**
 * Create JSON request for UpdateCase./*from  www  . j  a  v a2 s .  c  om*/
 *
 * @return JSON payload.
 * @throws JSONException thrown when parsing JSON String.
 */
private String getJsonPayload() throws JSONException {

    JSONObject jsonPayload = new JSONObject();

    String id = (String) messageContext.getProperty(Constants.ID);
    if (id != null && !id.isEmpty()) {
        jsonPayload.put(Constants.JSONKeys.ID, id);
    }
    String name = (String) messageContext.getProperty(Constants.NAME);
    if (name != null && !name.isEmpty()) {
        jsonPayload.put(Constants.JSONKeys.NAME, name.trim());
    }
    String description = (String) messageContext.getProperty(Constants.DESCRIPTION);
    if (description != null && !description.isEmpty()) {
        jsonPayload.put(Constants.JSONKeys.DESCRIPTION, description.trim());
    }
    String leadUser = (String) messageContext.getProperty(Constants.LEAD_USER);
    if (leadUser != null && !leadUser.isEmpty()) {
        jsonPayload.put(Constants.JSONKeys.LEAD_USER, leadUser.trim());
    }
    String customer = (String) messageContext.getProperty(Constants.CUSTOMER);
    if (customer != null && !customer.isEmpty()) {
        jsonPayload.put(Constants.JSONKeys.CUSTOMER, customer.trim());
    }
    String customFields = (String) messageContext.getProperty(Constants.CUSTOM_FIELDS);
    if (customFields != null && !customFields.isEmpty()) {

        jsonPayload.put(Constants.JSONKeys.CUSTOM_FIELD, new JSONObject(customFields));
    }
    String tags = (String) messageContext.getProperty(Constants.TAGS);
    if (tags != null && !tags.isEmpty()) {
        jsonPayload.put(Constants.JSONKeys.TAGS, new JSONArray(tags));
    }

    return jsonPayload.toString();
}

From source file:io.selendroid.SelendroidCapabilitiesTest.java

@Test
public void testInstanstiateFromJSON() throws Exception {
    JSONObject jsonSource = new JSONObject();
    jsonSource.put("browserName", "selendroid");
    jsonSource.put("platformVersion", DeviceTargetPlatform.ANDROID16.getApi());
    jsonSource.put("locale", "de_DE");
    jsonSource.put("aut", "io.selendroid.testapp:0.9.0");
    jsonSource.put("screenSize", "320x480");

    SelendroidCapabilities capa = new SelendroidCapabilities(jsonSource);
    // it is not set by default
    Assert.assertEquals(null, capa.getEmulator());
    Assert.assertEquals("selendroid", capa.getBrowserName());
    Assert.assertEquals("16", capa.getPlatformVersion());
    Assert.assertEquals("de_DE", capa.getLocale());
    Assert.assertEquals("io.selendroid.testapp:0.9.0", capa.getAut());
    Assert.assertEquals("320x480", capa.getScreenSize());
    Assert.assertEquals(5, capa.asMap().size());
}

From source file:org.uiautomation.ios.server.command.web.SetValueHandler.java

@Override
public JSONObject configurationDescription() throws JSONException {
    JSONObject desc = new JSONObject();
    desc.put("nativeEvents", "{boolean}, default to " + nativeEvents
            + ".true = UIAutomation native events will be used to enter the URL (slow) , Web =  WebKit remote debugging will be used.Faster but doesn't fire events.");
    return desc;/*from   w w  w.ja  v a  2 s.c  o  m*/
}

From source file:com.comcast.oscar.ber.OIDToJSONArray.java

/**
 *
 * @return JSON Array of the OID, DataType and Value */
public JSONArray toJSONArray() {

    JSONArray jaOID = new JSONArray();

    JSONObject joOID = new JSONObject();

    try {//  w w w  .  j  a va  2  s .  c o m

        this.sOID = this.sOID.replaceAll("^\\.", "");

        joOID.put(OID, this.sOID);

        joOID.put(DATA_TYPE, this.sDataType);

        //Clean up double quotes in the from and end of string
        this.sValue = this.sValue.replaceAll("^\"|\"$", "");
        joOID.put(VALUE, this.sValue);

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

    return jaOID.put(joOID);
}