0

I want to call another method if the condition is satisfied with the response of first method. But the response is in JSON and has many objects. I want to check if "RESPCODE" is "01" and if it is call a method.

Method:

@Override
public void onTransactionResponse(Bundle inResponse) {
    Log.d("LOG", "Payment Transaction is successful " + inResponse);

    if(inResponse.toString().equals("01")) {
        CheckoutProcess();
    } else {
        Toast.makeText(getApplicationContext(), "Transaction Failed ", Toast.LENGTH_LONG).show();

        Log.d("LOG", "Payment Transaction : " + inResponse);

    }
}

Response:

TXNAMOUNT = 1000.00
PAYMENTMODE = PPI
CURRENCY = INR 
TXNDATE = 2018-04-17 18:56:08.0
STATUS = TXN_SUCCESS
RESPCODE = 01
RESPMSG = Txn Success
GATEWAYNAME = WALLET
BANKTXNID = 
BANKNAME = WALLET
anothernode
  • 5,100
  • 13
  • 43
  • 62
user9658973
  • 3
  • 1
  • 5

1 Answers1

0

org.json library should be enough if it is only one or two properties you are interested in.

Use org.json library to parse it and create JsonObject:

JSONObject jsonObj = new JSONObject(<jsonStr>);

Now, use this object to get your values:

int respcode = jsonObj.getInt("RESPCODE");

You can see a complete example here:

How to parse JSON in Java

Robert
  • 353
  • 3
  • 12