Sample code for 30+ languages & platforms
Dart

Using JSON StringOf with Non-String Members

See more JSON Examples

If a JSON member is a boolean, integer, or null, using StringOf will return its string representation.

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  // Create JSON with members of different data types.
  final json = CkJsonObject();

  json.updateInt('a', 123);
  json.updateBool('b', true);
  json.updateNull('c');

  json.emitCompact = false;
  print(json.emit());

  // Resulting JSON:
  // {
  //   "a": 123,
  //   "b": true,
  //   "c": null
  // }

  final a = json.stringOf('a');
  print(a);

  final b = json.stringOf('b');
  print(b);

  final c = json.stringOf('c');
  print(c);

  // Output

  // 123
  // true
  // null

  // If you want to get the integer, boolean, or null value
  // you need to use the methods matching the data type
  final ival = json.intOf('a');
}