Sample code for 30+ languages & platforms
Android™

Load JSON Data at Path

See more JSON Examples

Demonstrates how to load JSON data into a path within a JSON database. For example, we begin with this JSON:
{
  "a": 1,
  "b": 2,
  "c": {
    "x": 1,
    "y": 2
  }
}
Then we load {"mm": 11, "nn": 22} to "c", and the result is this JSON:
{
  "a": 1,
  "b": 2,
  "c": {
    "mm": 11,
    "nn": 22
  }
}

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

    // Demonstrates how to load replace the data at a location within a JSON database.

    String p = "{\"a\": 1, \"b\": 2, \"c\": { \"x\": 1, \"y\": 2 } }";

    CkJsonObject json = new CkJsonObject();
    json.Load(p);
    json.put_EmitCompact(false);
    Log.i(TAG, json.emit());

    String q = "{\"mm\": 11, \"nn\": 22}";

    CkJsonObject c = new CkJsonObject();
    json.ObjectOf2("c",c);
    c.Load(q);

    // See that x and y are replaced with mm and nn.
    Log.i(TAG, json.emit());

  }

  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."
  }
}