Xson is a pure library for resolving json, bean generating will move to xson_builder.

Usage

Xson used like Gson.

Json member

classmirror type
JsonElementany
JsonNullnull
JsonPrimitiveint, double, bool and String
JsonObjectMap
JsonArrayList

other

classdescription
JsonSerializerjson serialize
JsonDeserializerjson deserialize
JsonFormatterformat json string
JsonInforesolve json structure to md5
JsonTypeenum of json type

A simple usage example:

import 'package:xson/xson.dart';

var jsonString1 = """
{"aa":100, "b":[1,2,3], "c":{"c1":[666]}}
""";

var json1 = {
  "aa": 100,
  "b": [1, 2, 3],
  "c": {
    "c1": [666]
  }
};

void main() {
  // string to json element

  // way1
  JsonElement element1 = xson.decodeToJsonElement(jsonString1);
  // way2
  JsonElement element2 = JsonElement.fromJsonString(jsonString1);
  // way3
  JsonElement element3 = JsonElement.fromJson(json1);

  // element to other type
  JsonObject object = element1.asObject; // {"aa": 100, "b": [1, 2, 3], "c": {"c1": [666]}};
  JsonArray array = object["b"].asArray; // [1,2,3]
  array[0].asInt; // 1

  // element to string
  print(element1.toString());
  print(element1.toJsonString(prettify: true, indent: 4));
  print(xson.encodeFromJsonElement(element1, prettify: true));

  // element to json dynamic
  element1.toJson();

  // traversal all nodes of element
  JsonSerializeCallback callback = (JsonElement node, dynamic parent, int depth) {
    // do something
  };
  element1.traversalChildrenNode(callback);
}

Libraries

xson
Support for doing something awesome. [...]