object-serialization

QDataStream unable to serialize data

可紊 提交于 2019-12-25 04:10:53
问题 I am trying to follow the tutorial here and serialize Qt objects. Here is my code: QFile file("/Users/kaustav/Desktop/boo.dat"); if (!file.open(QIODevice::WriteOnly)) { qDebug() << "Cannot open file for writing: " << qPrintable(file.errorString()) << endl; //no error message gets printed return 0; } QDataStream out(&file); // we will serialize the data into the file out.setVersion(QDataStream::Qt_5_3); //adding this makes no difference out << QString("the answer is"); // serialize a string

How does object serialize/unserialize work?

我们两清 提交于 2019-12-19 06:24:20
问题 I was reading about serialize/unserialize concepts of PHP. I was wondering how they are stored in the filesystem/db. I guess it is in the binary format. However, I wonder how entire class is stored? I understood that data in the data member can be stored but how are the methods stored? I mean, how does PHP know what code is written inside the function of say, someFunc() ? $obj = new ClassName(); $obj->someFunc(); $serial = serialize($obj); $unserialobj = unserialize($serial); $unserialobj-

How does object serialize/unserialize work?

99封情书 提交于 2019-12-19 06:24:11
问题 I was reading about serialize/unserialize concepts of PHP. I was wondering how they are stored in the filesystem/db. I guess it is in the binary format. However, I wonder how entire class is stored? I understood that data in the data member can be stored but how are the methods stored? I mean, how does PHP know what code is written inside the function of say, someFunc() ? $obj = new ClassName(); $obj->someFunc(); $serial = serialize($obj); $unserialobj = unserialize($serial); $unserialobj-

Serializing PHP object to JSON

荒凉一梦 提交于 2019-12-17 02:59:46
问题 So I was wandering around php.net for information about serializing PHP objects to JSON, when I stumbled across the new JsonSerializable Interface. It's only PHP >= 5.4 though, and I'm running in a 5.3.x environment. How is this sort of functionality achieved PHP < 5.4 ? I've not worked much with JSON yet, but I'm trying to support an API layer in an application, and dumping the data object ( that would otherwise be sent to the view ) into JSON would be perfect. If I attempt to serialize the

Incomplete PHP class when serializing object in sessions

爱⌒轻易说出口 提交于 2019-12-11 03:17:02
问题 I'm working on a shopping cart (Cart model). One of its protected properties is "_items", which holds an array of Product objects. They (Products) all get stored in DB for populating the session (using ZF, Zend_Session_SaveHandler_DbTable() etc.). public function addItem(Model_Product $product, $qty) { $qty = (int) $qty; $pId = $product->getId(); if ($qty > 0) { $this->_items[$pId] = array('product' => $product, 'qty' => $qty); } else { // if the quantity is zero (or less), remove item from

How to do a form POST to an MVC 3 application and obtain the deserialized class?

喜欢而已 提交于 2019-12-09 20:43:05
问题 I have the following form: <form id="MakeDocumentForm" name="MakeDocumentForm" action="Document/GetWordDocument" method="post" enctype="application/json"> <button type="submit" style="float:right;">Make Word Document</button> <textarea id="hiddenJson" name="hiddenJson" data-bind="text: ko.toJSON(viewModel.selectedDocument)" rows="5" cols="100" style="visibility:hidden;" > </textarea> </form> The data-bind attribute is knockoutjs - but this isn't important, the textarea correctly contains the

How to do a form POST to an MVC 3 application and obtain the deserialized class?

时光怂恿深爱的人放手 提交于 2019-12-04 12:26:17
I have the following form: <form id="MakeDocumentForm" name="MakeDocumentForm" action="Document/GetWordDocument" method="post" enctype="application/json"> <button type="submit" style="float:right;">Make Word Document</button> <textarea id="hiddenJson" name="hiddenJson" data-bind="text: ko.toJSON(viewModel.selectedDocument)" rows="5" cols="100" style="visibility:hidden;" > </textarea> </form> The data-bind attribute is knockoutjs - but this isn't important, the textarea correctly contains the JSON that is the serialized object. [HttpPost] public void GetWordDocument(DocumentModel hiddenJson) {

What is the difference between pickle and shelve?

对着背影说爱祢 提交于 2019-11-28 16:57:10
I am learning about object serialization for the first time. I tried reading and 'googling' for differences in the modules pickle and shelve but I am not sure I understand it. When to use which one? Pickle can turn every python object into stream of bytes which can be persisted into a file. Then why do we need the module shelve? Isn't pickle faster? pickle is for serializing some object (or objects) as a single bytestream in a file. shelve builds on top of pickle and implements a serialization dictionary where objects are pickled, but associated with a key (some string), so you can load your

Java object Serialization and inheritance

随声附和 提交于 2019-11-27 19:19:42
Say you have these two classes, Foo and Bar where Bar extends Foo and implements Serializable class Foo { public String name; public Foo() { this.name = "Default"; } public Foo(String name) { this.name = name; } } class Bar extends Foo implements java.io.Serializable { public int id; public Bar(String name, int id) { super(name); this.id = id; } } Notice that Foo doesn't implement Serializable . So what happens when bar is serialized? public static void main(String[] args) throws Exception { FileOutputStream fStream=new FileOutputStream("objects.dat"); ObjectOutputStream oStream=new

What is the difference between pickle and shelve?

喜夏-厌秋 提交于 2019-11-27 09:56:22
问题 I am learning about object serialization for the first time. I tried reading and 'googling' for differences in the modules pickle and shelve but I am not sure I understand it. When to use which one? Pickle can turn every python object into stream of bytes which can be persisted into a file. Then why do we need the module shelve? Isn't pickle faster? 回答1: pickle is for serializing some object (or objects) as a single bytestream in a file. shelve builds on top of pickle and implements a