Anonymous user
JSON: Difference between revisions
→{{header|Crystal}}
Line 965:
=={{header|Crystal}}==
Before 1.0.0:
<lang Ruby>
require "
class Foo
Line 982 ⟶ 983:
</lang>
After 1.0.0:
<lang Ruby>
require "json"
class Foo
include JSON::Serializable
property num : Int64
property array : Array(String)
end
def json
foo = Foo.from_json(%({"num": 1, "array": ["a", "b"]}))
puts("#{foo.num} #{foo.array}")
puts(foo.to_json)
end
</lang>
Output:
<pre>1 ["a", "b"]
{"num":1,"array":["a","b"]}</pre>
|