개발

serialization/deserialization

팥빙구 2015. 3. 2. 12:03

Ruby Serialization


q = {name: "binibin", age: 22, company: "braincommerce"}

=> {:name=>"binibin", :age=>22, :company=>"braincommerce"}

q.to_json

=> "{\"name\":\"binibin\",\"age\":22,\"company\":\"braincommerce\”}"


Ruby Deserialization


JSON.parse(q.to_json)

=> {"name"=>"binibin", "age"=>22, "company"=>"braincommerce"}


Javascript Deserialization


j = JSON.parse("{\"name\":\"binibin\",\"age\":22,\"company\":\"braincommerce\"}");

=> Object {name: "binibin", age: 22, company: "braincommerce"}


Javascript Serialization


JSON.stringify(j) 

=> "{"name":"binibin","age":22,"company":"braincommerce"}"