开发者

How do I deserialize objects in Io?

I've found the serialized and justSerialized methods on Object and already successfu开发者_开发问答lly serialized objects to files, but I cannot find a matching deserialize method.

Is there none or am I just too stupid to find it?


I think doString or doMessage should do what you need (though I can't confirm this at moment because I don't have Io running on this machine).

For eg:

doString( yourSerializedString )

or

doMessage( yourSerializedString asMessage )


Update - Can now confirm that doString or doMessage does work. Full example below:

Foo.io

Foo := Object clone do (
    name ::= nil
)

serialize.io

doRelativeFile("Foo.io")

baz := Foo clone setName("baz")

// serialize "baz" object to file
File with("serialized.data") open write(baz serialized) close

restore_object.io

doRelativeFile("Foo.io")

baz := doString(
    File with("serialized.data") open readLines join
)


In fact you can also deserialize the object with doRelativeFile or doFile:

baz := doRelativeFile("serialized.data")

Because serialized data is just Io code.

/I3az/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜