xson 1.0.4

Dart native js
Flutter Android iOS web

Xson is a pure library for resolving json (like Gson), you can easily use Xson to encode/decode/generate/traversal/prettify/simpify by less code.

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);
}
0
likes
90
pub points
38%
popularity

Xson is a pure library for resolving json (like Gson), you can easily use Xson to encode/decode/generate/traversal/prettify/simpify by less code.

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

meiswind711108@gmail.com

License

BSD (LICENSE)

Dependencies

convert, crypto

More

Packages that depend on xson