Braintree/src/main/java/com/braintreepayments/api/models/PayPalAccountNonce.java
public static PayPalAccountNonce fromJson(String jsonString) throws JSONException {
        JSONObject jsonObj = new JSONObject(jsonString);
        PayPalAccountNonce payPalAccountNonce = new PayPalAccountNonce();

        if(jsonObj.has(PayPalAccountNonce.API_RESOURCE_KEY)) {
            payPalAccountNonce.fromJson(PayPalAccountNonce.getJsonObjectForType(API_RESOURCE_KEY, jsonObj));
        } else if(jsonObj.has(PayPalAccountNonce.PAYMENT_METHOD_DATA_KEY)) {
            JSONObject tokenObj = new JSONObject(new JSONObject(jsonString)
                    .getJSONObject(PayPalAccountNonce.PAYMENT_METHOD_DATA_KEY)
                    .getJSONObject(PayPalAccountNonce.TOKENIZATION_DATA_KEY)
                    .getString(PayPalAccountNonce.TOKEN_KEY));

            payPalAccountNonce.fromJson(PayPalAccountNonce.getJsonObjectForType(API_RESOURCE_KEY, tokenObj));
            JSONObject shippingAddress = jsonObj.optJSONObject(SHIPPING_ADDRESS_KEY);
            if (shippingAddress != null) {
                payPalAccountNonce.mShippingAddress = PostalAddressParser.fromJson(shippingAddress);
            }
        } else {
            throw new JSONException("Could not parse JSON for a payment method nonce");
        }

        return payPalAccountNonce;
    }
public static PayPalAccountNonce fromJson(String jsonString) throws JSONException {
        JSONObject jsonObj = new JSONObject(jsonString);
        PayPalAccountNonce payPalAccountNonce = new PayPalAccountNonce();

        if(jsonObj.has(PayPalAccountNonce.API_RESOURCE_KEY)) {
            payPalAccountNonce.fromJson(PayPalAccountNonce.getJsonObjectForType(API_RESOURCE_KEY, jsonObj));
        } else if(jsonObj.has(PayPalAccountNonce.PAYMENT_METHOD_DATA_KEY)) {
            JSONObject tokenObj = new JSONObject(new JSONObject(jsonString)
                    .getJSONObject(PayPalAccountNonce.PAYMENT_METHOD_DATA_KEY)
                    .getJSONObject(PayPalAccountNonce.TOKENIZATION_DATA_KEY)
                    .getString(PayPalAccountNonce.TOKEN_KEY));

            payPalAccountNonce.fromJson(PayPalAccountNonce.getJsonObjectForType(API_RESOURCE_KEY, tokenObj));
            JSONObject shippingAddress = jsonObj.optJSONObject(SHIPPING_ADDRESS_KEY);
            if (shippingAddress != null) {
                payPalAccountNonce.mShippingAddress = PostalAddressParser.fromJson(shippingAddress);
            }
        } else {
            throw new JSONException("Could not parse JSON for a payment method nonce");
        }

        return payPalAccountNonce;
    }
public static PayPalAccountNonce fromJson ( String jsonString ) throws JSONException { JSONObject jsonObj = new JSONObject ( jsonString ) ; PayPalAccountNonce payPalAccountNonce = new PayPalAccountNonce ( ) ; if ( jsonObj . has ( PayPalAccountNonce . API_RESOURCE_KEY ) ) { payPalAccountNonce . fromJson ( PayPalAccountNonce . getJsonObjectForType ( API_RESOURCE_KEY , jsonObj ) ) ; } else if ( jsonObj . has ( PayPalAccountNonce . PAYMENT_METHOD_DATA_KEY ) ) { JSONObject tokenObj = new JSONObject ( new JSONObject ( jsonString ) . getJSONObject ( PayPalAccountNonce . PAYMENT_METHOD_DATA_KEY ) . getJSONObject ( PayPalAccountNonce . TOKENIZATION_DATA_KEY ) . getString ( PayPalAccountNonce . TOKEN_KEY ) ) ; payPalAccountNonce . fromJson ( PayPalAccountNonce . getJsonObjectForType ( API_RESOURCE_KEY , tokenObj ) ) ; JSONObject shippingAddress = jsonObj . optJSONObject ( SHIPPING_ADDRESS_KEY ) ; if ( shippingAddress != null ) { payPalAccountNonce . mShippingAddress = PostalAddressParser . fromJson ( shippingAddress ) ; } } else { throw new JSONException ( "Could not parse JSON for a payment method nonce" ) ; } return payPalAccountNonce ; }
Convert an API response to a {@link PayPalAccountNonce}.

@param jsonString Raw JSON representation of a {@link PayPalAccountNonce}.
@return {@link PayPalAccountNonce} for use in payment method selection UIs.
Convert an API response to a { @link PayPalAccountNonce } .