Example usage for org.json JSONArray put

List of usage examples for org.json JSONArray put

Introduction

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

Prototype

public JSONArray put(Object value) 

Source Link

Document

Append an object value.

Usage

From source file:IoTatWork.AuCapTreeResource.java

/**
 * //from  w  ww. j  a va2 s  . c o m
 * @param auCapNode
 * @param jsonNodeTree 
 * @return
 */
private void getJsonAuCapVertexData(Vertex auCapNode, JSONObject jsonNodeTree) {
    try {

        Vertex detailsVertex = auCapNode.getEdges(Direction.OUT, DataMapper.DETAILS_LABEL).iterator().next()
                .getVertex(Direction.IN);
        jsonNodeTree.put("id", auCapNode.getId().toString().substring(1));
        jsonNodeTree.put("name", detailsVertex.getProperty(DataMapper.SUBJECT_ID).toString());
        JSONObject jsonVertexData = new JSONObject();
        jsonVertexData.put("edgeLabel", DataMapper.DEPENDENT_CAPABILIES_LABEL);

        //AuCapVertex
        jsonVertexData.put(DataMapper.CAPABILITY_ID, auCapNode.getProperty(DataMapper.CAPABILITY_ID));
        jsonVertexData.put(DataMapper.CAPABILITY_ISSUER, auCapNode.getProperty(DataMapper.CAPABILITY_ISSUER));
        jsonVertexData.put(DataMapper.CAPABILITY_ISSUE_TIME,
                auCapNode.getProperty(DataMapper.CAPABILITY_ISSUE_TIME));

        String status = (String) auCapNode.getProperty(DataMapper.STATUS);
        jsonVertexData.put(DataMapper.STATUS, status);

        /*
        if(status.equals(Status.REVOKED)){
           String revocationScope = (String) auCapNode.getProperty(DataMapper.REVOCATION_SCOPE);
           jsonVertexData.put(DataMapper.REVOCATION_SCOPE, revocationScope);
           if(revocationScope.equals(RevocationScope.ALL)){
              jsonVertexData.put(DataMapper.REVOKED_SINCE, auCapNode.getProperty(DataMapper.REVOKED_SINCE));
              jsonVertexData.put(DataMapper.DESCENDANT_REVOKED_SINCE, auCapNode.getProperty(DataMapper.DESCENDANT_REVOKED_SINCE));
           }else if(revocationScope.equals(RevocationScope.THIS)){
              jsonVertexData.put(DataMapper.REVOKED_SINCE, auCapNode.getProperty(DataMapper.REVOKED_SINCE));
           }else if(revocationScope.equals(RevocationScope.DESCENDANT)){
              jsonVertexData.put(DataMapper.DESCENDANT_REVOKED_SINCE, auCapNode.getProperty(DataMapper.DESCENDANT_REVOKED_SINCE));
           }
                   
        }
        */

        jsonVertexData.put(DataMapper.VALIDITY_START_TIME,
                auCapNode.getProperty(DataMapper.VALIDITY_START_TIME));
        jsonVertexData.put(DataMapper.VALIDITY_END_TIME, auCapNode.getProperty(DataMapper.VALIDITY_END_TIME));

        //AuCapDetails
        jsonVertexData.put(DataMapper.SUBJECT_ID, detailsVertex.getProperty(DataMapper.SUBJECT_ID));
        jsonVertexData.put(DataMapper.RESOURCE_ID, detailsVertex.getProperty(DataMapper.RESOURCE_ID));
        jsonVertexData.put(DataMapper.REVOCATION_SERVICE_URLS,
                detailsVertex.getProperty(DataMapper.REVOCATION_SERVICE_URLS));

        if (!auCapNode.getEdges(Direction.OUT, DataMapper.DEPENDENT_CAPABILIES_LABEL).iterator().hasNext()) {
            jsonVertexData.put("leaf", "leaf");
        }
        //         for(String prop : auCapNode.getPropertyKeys()){
        //            jsonVertexData.put(prop, auCapNode.getProperty(prop));
        //         }
        //         for(String prop : detailsVertex.getPropertyKeys()){
        //            if(!prop.equals(DataMapper.CAPABILITY_TOKEN))
        //               jsonVertexData.put(prop, detailsVertex.getProperty(prop));
        //         }
        JSONArray jsonArrayAccessRights = new JSONArray();
        for (Edge accessRightEdge : detailsVertex.getEdges(Direction.OUT, DataMapper.ACCESS_RIGHTS_LABEL)) {
            Vertex accesRightVertex = accessRightEdge.getVertex(Direction.IN);
            JSONObject jsonAccessRight = new JSONObject();
            for (String prop : accesRightVertex.getPropertyKeys()) {
                jsonAccessRight.put(prop, accesRightVertex.getProperty(prop));
            }
            jsonArrayAccessRights.put(jsonAccessRight);
        }
        jsonVertexData.put(DataMapper.ACCESS_RIGHTS_LABEL, jsonArrayAccessRights);
        jsonNodeTree.put("data", jsonVertexData);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.asd.littleprincesbeauty.data.Task.java

@Override
public JSONObject getLocalJSONFromContent() {
    String name = getName();/*  ww  w  .  ja v a 2 s .  com*/
    try {
        if (mMetaInfo == null) {
            // new task created from web
            if (name == null) {
                Log.w(TAG, "the note seems to be an empty one");
                return null;
            }

            JSONObject js = new JSONObject();
            JSONObject note = new JSONObject();
            JSONArray dataArray = new JSONArray();
            JSONObject data = new JSONObject();
            data.put(DataColumns.CONTENT, name);
            dataArray.put(data);
            js.put(GTaskStringUtils.META_HEAD_DATA, dataArray);
            note.put(NoteColumns.TYPE, Notes.TYPE_NOTE);
            js.put(GTaskStringUtils.META_HEAD_NOTE, note);
            return js;
        } else {
            // synced task
            JSONObject note = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
            JSONArray dataArray = mMetaInfo.getJSONArray(GTaskStringUtils.META_HEAD_DATA);

            for (int i = 0; i < dataArray.length(); i++) {
                JSONObject data = dataArray.getJSONObject(i);
                if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) {
                    data.put(DataColumns.CONTENT, getName());
                    break;
                }
            }

            note.put(NoteColumns.TYPE, Notes.TYPE_NOTE);
            return mMetaInfo;
        }
    } catch (JSONException e) {
        Log.e(TAG, e.toString());
        e.printStackTrace();
        return null;
    }
}

From source file:edu.asu.msse.gnayak2.main.CollectionSkeleton.java

public String callMethod(String request) {
    JSONObject result = new JSONObject();
    try {/*  w w w.  java2  s .com*/
        JSONObject theCall = new JSONObject(request);
        System.out.println(request);
        String method = theCall.getString("method");
        int id = theCall.getInt("id");
        JSONArray params = null;
        if (!theCall.isNull("params")) {
            params = theCall.getJSONArray("params");
            System.out.println(params);
        }
        result.put("id", id);
        result.put("jsonrpc", "2.0");
        if (method.equals("resetFromJsonFile")) {
            mLib.resetFromJsonFile();
            result.put("result", true);
            System.out.println("resetFromJsonCalled");
        } else if (method.equals("remove")) {
            String sName = params.getString(0);
            boolean removed = mLib.remove(sName);
            System.out.println(sName + " deleted");
            result.put("result", removed);
        } else if (method.equals("add")) {
            MovieImpl movie = new MovieImpl(params.getString(0));
            boolean added = mLib.add(movie);
            result.put("result", added);
        } else if (method.equals("get")) {
            String sName = params.getString(0);
            MovieImpl movie = mLib.get(sName);
            result.put("result", movie.toJson());
        } else if (method.equals("getNames")) {
            String[] names = mLib.getNames();
            JSONArray resArr = new JSONArray();
            for (int i = 0; i < names.length; i++) {
                resArr.put(names[i]);
            }
            result.put("result", resArr);
        } else if (method.equals("saveToJsonFile")) {
            boolean saved = mLib.saveToJsonFile();
            result.put("result", saved);
        } else if (method.equals("getModelInformation")) {
            //mLib.resetFromJsonFile();
            result.put("result", mLib.getModelInformation());
        } else if (method.equals("update")) {
            String movieJSONString = params.getString(0);
            Movie mo = new MovieImpl(movieJSONString);
            mLib.updateMovie(mo);
        } else if (method.equals("deleteAndAdd")) {
            String oldMovieJSONString = params.getString(0);
            String editedMovieJSONString = params.getString(1);
            boolean deletionSuccessful = false;
            boolean additionSuccessful = false;
            MovieImpl oldMovie = new MovieImpl(oldMovieJSONString);
            MovieImpl newMovie = new MovieImpl(editedMovieJSONString);
            deletionSuccessful = mLib.deleteMovie(oldMovie);
            additionSuccessful = mLib.add(newMovie);
            result.put("result", deletionSuccessful & additionSuccessful);
        }
    } catch (Exception ex) {
        System.out.println("exception in callMethod: " + ex.getMessage());
    }
    System.out.println("returning: " + result.toString());
    return "HTTP/1.0 200 Data follows\nServer:localhost:8080\nContent-Type:text/plain\nContent-Length:"
            + (result.toString()).length() + "\n\n" + result.toString();
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.AppObj.java

public static DbObject fromPickerResult(Context context, String action, ResolveInfo resolveInfo,
        Intent pickerResult) {//from   w  w  w.j a v a  2s .co  m
    long[] contactIds = pickerResult.getLongArrayExtra("contacts");
    String pkgName = resolveInfo.activityInfo.packageName;
    String className = resolveInfo.activityInfo.name;

    /**
     * TODO:
     * 
     * Identity Firewall Goes Here.
     * Membership details can be randomized in one of many ways.
     * The app (scrabble) may see games a set of gamers play together.
     * The app may always see random ids
     * The app may always see stable ids
     * 
     * Can also permute the cursor and member order.
     */

    JSONArray participantIds = new JSONArray();

    participantIds.put(App.instance().getLocalPersonId());
    for (long id : contactIds) {
        Maybe<Contact> annoyingContact = Contact.forId(context, id);
        try {
            Contact contact = annoyingContact.get();
            participantIds.put(contact.personId);
        } catch (NoValError e) {
            participantIds.put(Contact.UNKNOWN);
        }
    }
    JSONObject json = new JSONObject();
    try {
        json.put(Multiplayer.OBJ_MEMBERSHIP, (participantIds));
        json.put(ANDROID_ACTION, action);
        json.put(ANDROID_PACKAGE_NAME, pkgName);
        json.put(ANDROID_CLASS_NAME, className);
    } catch (JSONException e) {
        Log.d(TAG, "What? Impossible!", e);
    }
    return new DbObject(TYPE, json);
}

From source file:fr.arnaudguyon.xmltojsonlib.XmlToJson.java

private JSONObject convertTagToJson(Tag tag, boolean isListElement) {
    JSONObject json = new JSONObject();

    // Content is injected as a key/value
    if (tag.getContent() != null) {
        String path = tag.getPath();
        String name = getContentNameReplacement(path, DEFAULT_CONTENT_NAME);
        putContent(path, json, name, tag.getContent());
    }/* www .j a  v a  2  s . c om*/

    try {

        HashMap<String, ArrayList<Tag>> groups = tag.getGroupedElements(); // groups by tag names so that we can detect lists or single elements
        for (ArrayList<Tag> group : groups.values()) {

            if (group.size() == 1) { // element, or list of 1
                Tag child = group.get(0);
                if (isForcedList(child)) { // list of 1
                    JSONArray list = new JSONArray();
                    list.put(convertTagToJson(child, true));
                    String childrenNames = child.getName();
                    json.put(childrenNames, list);
                } else { // stand alone element
                    if (child.hasChildren()) {
                        JSONObject jsonChild = convertTagToJson(child, false);
                        json.put(child.getName(), jsonChild);
                    } else {
                        String path = child.getPath();
                        putContent(path, json, child.getName(), child.getContent());
                    }
                }
            } else { // list
                JSONArray list = new JSONArray();
                for (Tag child : group) {
                    list.put(convertTagToJson(child, true));
                }
                String childrenNames = group.get(0).getName();
                json.put(childrenNames, list);
            }
        }
        return json;

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

From source file:org.bcsphere.bluetooth.BCBluetooth.java

@Override
public boolean execute(final String action, final JSONArray json, final CallbackContext callbackContext)
        throws JSONException {
    try {/*from   ww w .  jav  a 2 s .c o  m*/
        if (bluetoothAPI != null) {
            if (isSetContext) {
                bluetoothAPI.setContext(myContext);
                isSetContext = false;
            }
            if (action.equals("getCharacteristics")) {
                bluetoothAPI.getCharacteristics(json, callbackContext);
            } else if (action.equals("getDescriptors")) {
                bluetoothAPI.getDescriptors(json, callbackContext);
            } else if (action.equals("removeServices")) {
                bluetoothAPI.removeServices(json, callbackContext);
            }
            if (action.equals("stopScan")) {
                bluetoothAPI.stopScan(json, callbackContext);
            } else if (action.equals("getConnectedDevices")) {
                bluetoothAPI.getConnectedDevices(json, callbackContext);
            }

            cordova.getThreadPool().execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        if (action.equals("startScan")) {
                            bluetoothAPI.startScan(json, callbackContext);
                        } else if (action.equals("connect")) {
                            bluetoothAPI.connect(json, callbackContext);
                        } else if (action.equals("disconnect")) {
                            bluetoothAPI.disconnect(json, callbackContext);
                        } else if (action.equals("getServices")) {
                            bluetoothAPI.getServices(json, callbackContext);
                        } else if (action.equals("writeValue")) {
                            bluetoothAPI.writeValue(json, callbackContext);
                        } else if (action.equals("readValue")) {
                            bluetoothAPI.readValue(json, callbackContext);
                        } else if (action.equals("setNotification")) {
                            bluetoothAPI.setNotification(json, callbackContext);
                        } else if (action.equals("getDeviceAllData")) {
                            bluetoothAPI.getDeviceAllData(json, callbackContext);
                        } else if (action.equals("addServices")) {
                            bluetoothAPI.addServices(json, callbackContext);
                        } else if (action.equals("getRSSI")) {
                            bluetoothAPI.getRSSI(json, callbackContext);
                        }
                    } catch (Exception e) {
                        Tools.sendErrorMsg(callbackContext);
                    } catch (Error e) {
                        Tools.sendErrorMsg(callbackContext);
                    }
                }
            });
        }

        if (action.equals("addEventListener")) {
            String eventName = Tools.getData(json, Tools.EVENT_NAME);
            if (eventName.equals("newadvpacket")) {
                newadvpacketContext = callbackContext;
            } else if (eventName.equals("disconnect")) {
                disconnectContext = callbackContext;
            }
            if (bluetoothAPI != null) {
                bluetoothAPI.addEventListener(json, callbackContext);
            }
            return true;
        }

        if (action.equals("getEnvironment")) {
            JSONObject jo = new JSONObject();
            if (this.webView.page != null) {
                jo.put("deviceAddress", this.webView.page.deviceAddress);
                jo.put("deviceType", this.webView.page.deviceType);
                jo.put("api", versionOfAPI);
            } else {
                jo.put("deviceAddress", "N/A");
                jo.put("deviceType", "N/A");
                jo.put("api", versionOfAPI);
            }
            callbackContext.success(jo);
            return true;
        }
        if (action.equals("openBluetooth")) {
            if (!bluetoothAdapter.isEnabled()) {
                bluetoothAdapter.enable();
            }
            Tools.sendSuccessMsg(callbackContext);
            return true;
        }
        if (action.equals("getBluetoothState")) {
            Log.i(TAG, "getBluetoothState");
            JSONObject obj = new JSONObject();
            if (bluetoothAdapter.isEnabled()) {
                Tools.addProperty(obj, Tools.BLUETOOTH_STATE, Tools.IS_TRUE);
                callbackContext.success(obj);
            } else {
                Tools.addProperty(obj, Tools.BLUETOOTH_STATE, Tools.IS_FALSE);
                callbackContext.success(obj);
            }
            return true;
        }
        if (action.equals("startClassicalScan")) {
            Log.i(TAG, "startClassicalScan");
            if (bluetoothAdapter.isEnabled()) {
                if (bluetoothAdapter.startDiscovery()) {
                    callbackContext.success();
                } else {
                    callbackContext.error("start classical scan error!");
                }
            } else {
                callbackContext.error("your bluetooth is not open!");
            }
        }
        if (action.equals("stopClassicalScan")) {
            Log.i(TAG, "stopClassicalScan");
            if (bluetoothAdapter.isEnabled()) {
                if (bluetoothAdapter.cancelDiscovery()) {
                    callbackContext.success();
                } else {
                    callbackContext.error("stop classical scan error!");
                }
            } else {
                callbackContext.error("your bluetooth is not open!");
            }
        }
        if (action.equals("rfcommConnect")) {
            String deviceAddress = Tools.getData(json, Tools.DEVICE_ADDRESS);
            String securestr = Tools.getData(json, Tools.SECURE);
            String uuidstr = Tools.getData(json, Tools.UUID);
            boolean secure = false;
            if (securestr != null && securestr.equals("true")) {
                secure = true;
            }
            Log.i(TAG, "connect to " + deviceAddress);
            BluetoothDevice device = bluetoothAdapter.getRemoteDevice(deviceAddress);
            BluetoothSerialService classicalService = classicalServices.get(deviceAddress);

            if (device != null && classicalService == null) {
                classicalService = new BluetoothSerialService();
                classicalService.disconnectCallback = disconnectContext;
                classicalServices.put(deviceAddress, classicalService);
            }

            if (device != null) {
                classicalService.connectCallback = callbackContext;
                classicalService.connect(device, uuidstr, secure);
            } else {
                callbackContext.error("Could not connect to " + deviceAddress);
            }
        }
        if (action.equals("rfcommDisconnect")) {
            String deviceAddress = Tools.getData(json, Tools.DEVICE_ADDRESS);
            BluetoothSerialService service = classicalServices.get(deviceAddress);
            if (service != null) {
                service.connectCallback = null;
                service.stop();
                classicalServices.remove(deviceAddress);
                callbackContext.success();
            } else {
                callbackContext.error("Could not disconnect to " + deviceAddress);
            }
        }
        if (action.equals("rfcommListen")) {
            String name = Tools.getData(json, Tools.NAME);
            String uuidstr = Tools.getData(json, Tools.UUID);
            String securestr = Tools.getData(json, Tools.SECURE);
            boolean secure = false;
            if (securestr.equals("true")) {
                secure = true;
            }
            BluetoothSerialService service = new BluetoothSerialService();
            service.listen(name, uuidstr, secure, this);
            acceptServices.put(name + uuidstr, service);
        }
        if (action.equals("rfcommUnListen")) {
            String name = Tools.getData(json, Tools.NAME);
            String uuidstr = Tools.getData(json, Tools.UUID);
            BluetoothSerialService service = acceptServices.get(name + uuidstr);
            if (service != null) {
                service.stop();
            }
        }
        if (action.equals("rfcommWrite")) {
            String deviceAddress = Tools.getData(json, Tools.DEVICE_ADDRESS);
            BluetoothSerialService service = classicalServices.get(deviceAddress);
            if (service != null) {
                String data = Tools.getData(json, Tools.WRITE_VALUE);
                service.write(Tools.decodeBase64(data));
                callbackContext.success();
            } else {
                callbackContext.error("there is no connection on device:" + deviceAddress);
            }
        }
        if (action.equals("rfcommRead")) {
            String deviceAddress = Tools.getData(json, Tools.DEVICE_ADDRESS);
            BluetoothSerialService service = classicalServices.get(deviceAddress);
            if (service != null) {
                byte[] data = new byte[2048];
                byte[] predata = service.buffer.array();
                for (int i = 0; i < service.bufferSize; i++) {
                    data[i] = predata[i];
                }

                JSONObject obj = new JSONObject();
                //Tools.addProperty(obj, Tools.DEVICE_ADDRESS, deviceAddress);
                Tools.addProperty(obj, Tools.VALUE, Tools.encodeBase64(data));
                Tools.addProperty(obj, Tools.DATE, Tools.getDateString());
                callbackContext.success(obj);
                service.bufferSize = 0;
                service.buffer.clear();
            } else {
                callbackContext.error("there is no connection on device:" + deviceAddress);
            }
        }
        if (action.equals("rfcommSubscribe")) {
            String deviceAddress = Tools.getData(json, Tools.DEVICE_ADDRESS);
            BluetoothSerialService service = classicalServices.get(deviceAddress);
            if (service != null) {
                service.dataAvailableCallback = callbackContext;
            } else {
                callbackContext.error("there is no connection on device:" + deviceAddress);
            }
        }
        if (action.equals("rfcommUnsubscribe")) {
            String deviceAddress = Tools.getData(json, Tools.DEVICE_ADDRESS);
            BluetoothSerialService service = classicalServices.get(deviceAddress);
            if (service != null) {
                service.dataAvailableCallback = null;
            } else {
                callbackContext.error("there is no connection on device:" + deviceAddress);
            }
        }
        if (action.equals("getPairedDevices")) {
            try {
                Log.i(TAG, "getPairedDevices");
                JSONArray ary = new JSONArray();
                Set<BluetoothDevice> devices = bluetoothAdapter.getBondedDevices();
                Iterator<BluetoothDevice> it = devices.iterator();
                while (it.hasNext()) {
                    BluetoothDevice device = (BluetoothDevice) it.next();
                    JSONObject obj = new JSONObject();
                    Tools.addProperty(obj, Tools.DEVICE_ADDRESS, device.getAddress());
                    Tools.addProperty(obj, Tools.DEVICE_NAME, device.getName());
                    ary.put(obj);
                }
                callbackContext.success(ary);
            } catch (Exception e) {
                Tools.sendErrorMsg(callbackContext);
            } catch (java.lang.Error e) {
                Tools.sendErrorMsg(callbackContext);
            }
        } else if (action.equals("createPair")) {
            Log.i(TAG, "createPair");
            String deviceAddress = Tools.getData(json, Tools.DEVICE_ADDRESS);
            JSONObject obj = new JSONObject();
            BluetoothDevice device = bluetoothAdapter.getRemoteDevice(deviceAddress);
            if (Tools.creatBond(device.getClass(), device)) {
                Tools.addProperty(obj, Tools.DEVICE_ADDRESS, device.getAddress());
                callbackContext.success(obj);
            } else {
                Tools.addProperty(obj, Tools.DEVICE_ADDRESS, device.getAddress());
                callbackContext.error(obj);
            }
        } else if (action.equals("removePair")) {
            Log.i(TAG, "removePair");
            String deviceAddress = Tools.getData(json, Tools.DEVICE_ADDRESS);
            JSONObject obj = new JSONObject();
            BluetoothDevice device = bluetoothAdapter.getRemoteDevice(deviceAddress);
            if (Tools.removeBond(device.getClass(), device)) {
                Tools.addProperty(obj, Tools.DEVICE_ADDRESS, device.getAddress());
                callbackContext.success(obj);
            } else {
                Tools.addProperty(obj, Tools.DEVICE_ADDRESS, device.getAddress());
                callbackContext.error(obj);
            }
        }
    } catch (Exception e) {
        Tools.sendErrorMsg(callbackContext);
    } catch (Error e) {
        Tools.sendErrorMsg(callbackContext);
    }
    return true;
}

From source file:com.chaosinmotion.securechat.server.json.DeviceReturnResult.java

public JSONObject returnData() {
    JSONArray array = new JSONArray();
    for (JSONObject m : devices) {
        array.put(m);
    }// w w  w.j a v  a2s .  c  o m

    JSONObject obj = new JSONObject();
    obj.put("devices", array);
    obj.put("userid", userid);
    return obj;
}

From source file:com.mirasense.scanditsdk.plugin.SubViewPickerController.java

@Override
public void didEnter(String entry) {
    PluginResult result;/*w w w. j  a  va2s  .c  o m*/
    if (mLegacyMode) {
        JSONArray args = new JSONArray();
        args.put(entry);
        args.put("UNKNOWN");
        result = Marshal.createOkResult(args);
    } else {
        JSONArray args = Marshal.createEventArgs(ScanditSDK.DID_MANUAL_SEARCH_EVENT, entry);
        result = Marshal.createOkResult(args);
    }
    mCallbackContext.sendPluginResult(result);
    if (!mContinuousMode) {
        this.close();
    }

}

From source file:com.mirasense.scanditsdk.plugin.SubViewPickerController.java

@Override
public void didScan(ScanSession session) {
    // don't do anything if there is a pending close operation. otherwise we will deadlock
    if (mPendingClose.get()) {
        return;/*from  w ww .j  av a  2  s .c  om*/
    }
    PluginResult result;
    if (mLegacyMode) {
        JSONArray args = new JSONArray();
        Barcode code = session.getNewlyRecognizedCodes().get(0);
        args.put(code.getData());
        args.put(Code.symbologyToString(code.getSymbology(), code.isGs1DataCarrier()));
        args.put(code.getSymbologyName());
        result = Marshal.createOkResult(args);
    } else {
        JSONArray eventArgs = Marshal.createEventArgs(ScanditSDK.DID_SCAN_EVENT,
                ResultRelay.jsonForSession(session));
        result = Marshal.createOkResult(eventArgs);
    }

    int nextState = sendPluginResultBlocking(result);
    if (!mContinuousMode) {
        nextState = PickerStateMachine.PAUSED;
    }
    mPickerStateMachine.switchToNextScanState(nextState, session);
    Marshal.rejectCodes(session, mRejectedCodeIds);
    if (!mContinuousMode) {
        removeSubviewPicker();
    }
}

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. jav a  2s.  com

        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);
}