るりまサーチ (Ruby 2.5.0)

最速Rubyリファレンスマニュアル検索!
4件ヒット [1-4件を表示] (0.022秒)

別のキーワード

  1. time parse
  2. csv parse
  3. ripper parse
  4. parser parse
  5. psych parse_stream

クラス

モジュール

キーワード

検索結果

JSON.parser -> JSON::Ext::Parser (18610.0)

JSON ライブラリがパーサとして使用するクラスを返します。

...
JSON
ライブラリがパーサとして使用するクラスを返します。

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

JSON
.parser # => JSON::Ext::Parser
//}...

JSON::Parser.new(source, options => {}) -> JSON::Parser (9328.0)

パーサを初期化します。

...も付加情報を生成しません。デフォルトは真です。
: :object_class
JSON
のオブジェクトを変換するクラスを指定します。デフォルトは Hash です。
: :array_class
JSON
の配列を変換するクラスを指定します。デフォルトは Array です...
...文字列を指定します。

@param options オプションを指定するためのハッシュです。

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

parser = JSON::Parser.new(DATA.read)
print parser.source

# => {
# => "Tanaka": {
# => "name":"tanaka",
# => "age":20
# => },
# => "Suzuki":...
..."age":25
}
}
//}

//emlist[例 object_class を指定する][ruby]{
require 'json'

class Person
attr_accessor :name, :age

def []=(key, value)
instance_variable_set("@#{key}", value)
end
end

parser = JSON::Parser.new(DATA.read, object_class: Person)
person = parser.parse
person.class...

JSON.[](object, options) -> object (46.0)

文字列のように扱えるデータを受け取った場合は Ruby のオブジェクトに変換して返します。 そうでない場合は JSON に変換して返します。

... JSON に変換して返します。

@param object 任意のオブジェクト指定可能です。

@param options JSON.#parse, JSON.#generate の説明を参照してください。

//emlist[例][ruby]{
require "json"
string=<<JSON
{ "a":1, "b":2, "c":3 }
JSON

hash = { a: 1, b: 2, c: 3 }

JSON
[s...
...# => Hash
JSON
[string] # => {"a"=>1, "b"=>2, "c"=>3}
JSON
[string, symbolize_names: true] # => {:a=>1, :b=>2, :c=>3}
JSON
[hash].class # => String
JSON
[hash] # => "{\"a\":1,\"b\":2,\"c\":3}"
//}

@see JSON.#parse, JSON.#generate...

JSON.create_id -> String (28.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(...
...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_...