るりまサーチ

最速Rubyリファレンスマニュアル検索!
36件ヒット [1-36件を表示] (0.039秒)
トップページ > クエリ:to[x] > クエリ:json_create[x]

別のキーワード

  1. json to_json
  2. json state
  3. json parser
  4. json generate
  5. json parse

ライブラリ

キーワード

検索結果

JSON::Generator::GeneratorMethods::String::Extend.json_create(hash) -> String (24107.0)

JSON のオブジェクトから Ruby の文字列を生成して返します。

...のオブジェクトから Ruby の文字列を生成して返します。

@param hash キーとして "raw" という文字列を持ち、その値として数値の配列を持つハッシュを指定します。

require 'json'
String.json_create({"raw" => [0x41, 0x42, 0x43]}) # => "ABC"...

JSON.create_id -> String (34.0)

json_create メソッドで使用するクラスを決定するために使用する値を返します。

...
json_create
メソッドで使用するクラスを決定するために使用する値を返します。

デフォルトは "json_class" です。

//emlist[例][ruby]{
require "json"

class User
attr :id, :name
def initialize(id, name)
@id, @name = id, name
end

def self.json_create(...
...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.pars...

JSON.create_id=(identifier) (28.0)

json_create メソッドで使用するクラスを決定するために使用する値をセットします。

...
json_create
メソッドで使用するクラスを決定するために使用する値をセットします。

@param 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_id # => "my_json_class"
puts (1..5).to_json # => {"my_json_class":"Range","a":[1,5,false]}
//}...