Package blackberry.common.util.json4j

Examples of blackberry.common.util.json4j.JSONArray


     * *param array An array instance to populate instead of creating a new one.
     *
     * @throws JSONException Thrown if a parse error occurs, such as a malformed JSON array.
     */
    public JSONArray parseArray(boolean ordered, JSONArray array) throws JSONException {
        JSONArray result = null;
        if(array != null){
            result = array;
        } else {
            result = new JSONArray();
        }

        try {
            if (lastToken != Token.TokenBrackL) throw new JSONException("Expecting '[' " + tokenizer.onLineCol());
            lastToken = tokenizer.next();
            while (true) {
                if (lastToken == Token.TokenEOF) throw new JSONException("Unterminated array " + tokenizer.onLineCol());

                /**
                 * End of the array.
                 */
                if (lastToken == Token.TokenBrackR) {
                    lastToken = tokenizer.next();
                    break;
                }

                Object val = parseValue(ordered);
                result.add(val);

                if (lastToken == Token.TokenComma) {
                    lastToken = tokenizer.next();
                } else if (lastToken != Token.TokenBrackR) {
                    throw new JSONException("expecting either ',' or ']' " + tokenizer.onLineCol());
View Full Code Here


        String method = request.getMethodName();
        Object[] args = request.getArgs();
        String msg = "";
        int code = JSExtensionReturnValue.SUCCESS;
        JSONObject data = new JSONObject();
        JSONArray dataArray = new JSONArray();
        JSONObject returnValue = null;

        PaymentEngine engine = PaymentSystem.getInstance();

        if( engine == null ) {
            throw new IllegalArgumentException(
                    "Sorry, in-app purchases are unavailable. Make sure BlackBerry App World v2.1 or higher is installed on your device." );
        }

        if( !SUPPORTED_METHODS.contains( method ) ) {
            throw new WidgetException( "Undefined method: " + method );
        }

        try {
            if( method.equals( FUNCTION_PURCHASE ) ) {
                String digitalGoodID = (String) request.getArgumentByName( KEY_DG_ID );
                String digitalGoodSKU = (String) request.getArgumentByName( KEY_DG_SKU );
                String digitalGoodName = (String) request.getArgumentByName( KEY_DG_NAME );
                String metaData = (String) request.getArgumentByName( KEY_METADATA );
                String purchaseAppName = (String) request.getArgumentByName( KEY_APP_NAME );
                String purchaseAppIcon = (String) request.getArgumentByName( KEY_APP_ICON );

                PurchaseArgumentsBuilder arguments = new PurchaseArgumentsBuilder().withDigitalGoodId( digitalGoodID )
                        .withDigitalGoodName( digitalGoodName ).withDigitalGoodSku( digitalGoodSKU ).withMetadata( metaData )
                        .withPurchasingAppName( purchaseAppName )
                        .withPurchasingAppIcon( ( purchaseAppIcon != null ? Bitmap.getBitmapResource( purchaseAppIcon ) : null ) );

                // Blocking call: engine.purchase() invokes AppWorld screen.
                Purchase successfulPurchase = engine.purchase( arguments.build() );
                String purchaseJSON = purchaseToJSONString( successfulPurchase );

                data = new JSONObject( purchaseJSON );
                code = JSExtensionReturnValue.SUCCESS;
                msg = "Purchase Successful";
            } else if( method.equals( FUNCTION_GETEXISTINGPURCHASES ) ) {
                String refresh = (String) request.getArgumentByName( KEY_REFRESH );
                // Blocking call: engine.getExistingPurchases() invokes AppWorld screen.
                Purchase[] purchases = engine.getExistingPurchases( parseBoolean( refresh ) );

                if( purchases.length != 0 ) {
                    for( int i = 0; i < purchases.length; i++ ) {
                        String purchaseJSON = "";
                        purchaseJSON += purchaseToJSONString( purchases[ i ] );
                        JSONObject temp = new JSONObject( purchaseJSON );
                        dataArray.add( temp );
                    }
                }
            } else if( method.equals( new String( FUNCTION_GETMODE ) ) ) {
                data.put( "developmentMode", PaymentSystem.getMode() );
                code = JSExtensionReturnValue.SUCCESS;
View Full Code Here

     * @param arr
     * @return JSONArray
     * @throws JSONException
     */
    public static JSONArray convertObjectArrayToJSONArray( ObjectBase[] arr ) throws JSONException {
        JSONArray jsonArr = new JSONArray();

        if( arr != null ) {
            for( int i = 0; i < arr.length; i++ ) {
                if( arr[ i ] != null ) {
                    jsonArr.add( arr[ i ].getJSONObject() );
                }      
            }
        }

        return jsonArr;
View Full Code Here

TOP

Related Classes of blackberry.common.util.json4j.JSONArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.