PhpJsonEncoder class final

Writes the bytes of PHP's json_encode() for a Dart value in one pass: the same output as jsonEncode followed by phpJsonFromDart, without the intermediate string and its rewrite (on a 1 MB response the rewrite cost more than the encoding itself).

Values: null, bool, num (finite), String, List, Map with string keys and PhpObject; anything else goes through toEncodable once, as dart:convert does, or throws JsonUnsupportedObjectError. A cycle throws JsonCyclicError.

With emptyMapsAsArrays (the default), an empty map is [], as an empty PHP array encodes: Dart maps stand for PHP arrays in a port. A PhpObject is always an object, so PhpObject('stdClass', {}) is {} like PHP's (object) []. escapeSlashes false is JSON_UNESCAPED_SLASHES.

Constructors

PhpJsonEncoder({Object? toEncodable(Object? nonEncodable)?, bool emptyMapsAsArrays = true, bool escapeSlashes = true})
const

Properties

emptyMapsAsArrays → bool
final
escapeSlashes → bool
final
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
toEncodable → Object? Function(Object? nonEncodable)?
Converts a value the encoder does not know into one it does (a DateTime into a string, a model into a map). Applied once per value.
final

Methods

convert(Object? value) → String
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited