Sample code for 30+ languages & platforms
Android™

JSON Parsing with Sample Data for a Merchant/Payment Transaction

See more JSON Examples

Demonstrates how to load the following JSON into a JSON object and access the values for this document:
{
"id":"8a829449561d9dcb01571dbee3b275b1",
"paymentType":"DB",
"paymentBrand":"VISA",
"amount":"156.00",
"currency":"EUR",
"merchantTransactionId":"E8A39B31-6FA3-4014-A195-3074DF5BF7A1",
"result":{
	"code":"000.100.110",
	"description":"Request successfully processed in 'Merchant in Integrator Test Mode'"
},
"resultDetails":{
	"ConnectorTxID3":"12311312",
	"ConnectorTxID1":"717473"
},
"card":{
	"bin":"420000",
	"last4Digits":"0000",
	"holder":"Andreas",
	"expiryMonth":"12",
	"expiryYear":"2018"
},
"risk":{
	"score":"100"
},
"buildNumber":"4b471ea5366e5e9c9a21392a39769f8d7b40b4e8@2016-09-08 13:31:54 +0000",
"timestamp":"2016-09-12 09:33:52+0000",
}

Chilkat Android™ Downloads

Android™
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    boolean success = false;

    CkJsonObject json = new CkJsonObject();

    // Load the JSON into the object.
    // Call json.Load to load from a string rather than a file...
    success = json.LoadFile("qa_data/json/merchantPayment.json");
    // We are assuming success..

    // Get the easy stuff:
    Log.i(TAG, "id: " + json.stringOf("id"));
    Log.i(TAG, "paymentType: " + json.stringOf("paymentType"));
    Log.i(TAG, "currency: " + json.stringOf("currency"));
    Log.i(TAG, "buildNumber: " + json.stringOf("buildNumber"));

    // Get information that's nested within a sub-object:
    Log.i(TAG, "result: code: " + json.stringOf("result.code"));
    Log.i(TAG, "result: description: " + json.stringOf("result.description"));

    Log.i(TAG, "card: bin: " + json.stringOf("card.bin"));
    Log.i(TAG, "card: last4Digits: " + json.stringOf("card.last4Digits"));

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}