HaxeDoc2

(やまだぃちぅ) #1
haxe.ds.StringMap:bfollowed by the name-value pairs, followed byh(e.g.by1:xi2y1:knh
for{"x" => 2, "k" => null})

haxe.ds.IntMap:qfollowed by the key-value pairs, followed byh. Each key is represented
as:<int>(e.g.q:4n:5i45:6i7hfor{4 => null, 5 => 45, 6 => 7})

haxe.ds.ObjectMap:Mfollowed by serialized value pairs representing the key and value,
followed byh

haxe.io.Bytes:sfollowed by the length of the base64 encoded bytes, then:and the byte rep-
resentation using the codesA-Za-z0-9%(e.g.s3:AAAfor 2 bytes equal to 0 ,s10:SGVsbG8gIQ
forhaxe.io.Bytes.ofString("Hello !"))

exception:xfollowed by the exception value

class instance:cfollowed by the serialized class name, followed by the name-value pairs of the
fields, followed byg(e.g.cy5:Pointy1:xzy1:yzgfornew Point(0, 0)(having two
integer fieldsxandy)

enum instance (by name):wfollowed by the serialized enum name, followed by the serialized
constructor name, followed by the number of arguments, followed by the argument values
(e.g.wy3:Fooy1:A0forFoo.A(with no arguments),wy3:Fooy1:B2i4nforFoo.B(4,null))

enum instance (by index): jfollowed by the serialized enum name, followed by:, followed
by the constructor index, followed by the number of arguments, followed by the argu-
ment values (e.g. wy3:Foo0:0forFoo.A(with no arguments),wy3:Foo1:2i4nfor
Foo.B(4,null))

custom:Cfollowed by the class name, followed by the custom serialized data, followed byg

cache references: rfollowed by the cache index

10.8 Json..............................................


Haxe provides built-in support for (de-)serializingJSON^2 data via thehaxe.Jsonclass.

10.8.1 Parsing JSON


Use thehaxe.Json.parsestatic method to parseJSONdata and obtain a Haxe value from it:

1 class Main {
2 static function main() {
3 var s = ’{"rating": 5}’;
4 var o = haxe.Json.parse(s);
5 trace(o); // { rating: 5 }
6 }
7 }


Note that the type of the object returned byhaxe.Json.parseisDynamic, so if the struc-
ture of our data is well-known, we may want to specify a type using anonymous structures (2.5).
This way we provide compile-time checks for accessing our data and most likely more optimal
code generation, because compiler knows about types in a structure:

(^2) http://en.wikipedia.org/wiki/JSON

Free download pdf