33件ヒット
[1-33件を表示]
(0.117秒)
検索結果
-
Psych
. to _ json(o) -> String (18202.0) -
Ruby のオブジェクト o を JSON の文字列に変換します。
Ruby のオブジェクト o を JSON の文字列に変換します。
@param o 変換対象となるオブジェクト -
JSON
. create _ id=(identifier) (6213.0) -
json_create メソッドで使用するクラスを決定するために使用する値をセットします。
... identifier 識別子を指定します。
//emlist[例][ruby]{
require "json"
require "json/add/core"
JSON.create_id # => "json_class"
puts (1..5).to_json # => {"json_class":"Range","a":[1,5,false]}
JSON.create_id = "my_json_class" # => "my_json_class"
JSON.create_i......d # => "my_json_class"
puts (1..5).to_json # => {"my_json_class":"Range","a":[1,5,false]}
//}... -
JSON
. create _ id -> String (6113.0) -
json_create メソッドで使用するクラスを決定するために使用する値を返します。
...。
//emlist[例][ruby]{
require "json"
class User
attr :id, :name
def initialize(id, name)
@id, @name = id, name
end
def self.json_create(object)
new(object['id'], object["name"])
end
def as_json(*)
{
JSON.create_id => self.class.name,
"id" => id,
"name......" => name,
}
end
def to_json(*)
as_json.to_json
end
end
json = JSON.generate(User.new(1, "tanaka"))
json # => "{\"json_class\":\"User\",\"id\":1,\"name\":\"tanaka\"}"
JSON.parse(json, create_additions: true)
# => #<User:0x0000557709b269e0 @id=1, @name="tanaka">
//}...