クラス
- BigDecimal (1)
- Class (1)
- Complex (1)
- Date (1)
- DateTime (1)
- Exception (1)
-
JSON
:: Parser (2) -
JSON
:: State (29) - OpenStruct (1)
- Range (1)
- Rational (1)
- Regexp (1)
- Struct (1)
- Symbol (1)
- Time (1)
モジュール
-
JSON
:: Generator :: GeneratorMethods :: Array (1) -
JSON
:: Generator :: GeneratorMethods :: FalseClass (1) -
JSON
:: Generator :: GeneratorMethods :: Float (1) -
JSON
:: Generator :: GeneratorMethods :: Hash (1) -
JSON
:: Generator :: GeneratorMethods :: Integer (1) -
JSON
:: Generator :: GeneratorMethods :: NilClass (1) -
JSON
:: Generator :: GeneratorMethods :: Object (1) -
JSON
:: Generator :: GeneratorMethods :: String (3) -
JSON
:: Generator :: GeneratorMethods :: TrueClass (1)
キーワード
- [] (1)
- []= (1)
-
allow
_ nan? (1) -
array
_ nl (1) -
array
_ nl= (1) -
ascii
_ only? (1) -
buffer
_ initial _ length (1) -
buffer
_ initial _ length= (1) -
check
_ circular? (1) - configure (1)
- depth (1)
- depth= (1)
- generate (1)
- indent (1)
- indent= (1)
-
json
_ creatable? (1) -
max
_ nesting (1) -
max
_ nesting= (1) - merge (1)
-
object
_ nl (1) -
object
_ nl= (1) - parse (1)
-
quirks
_ mode (1) -
quirks
_ mode= (1) -
quirks
_ mode? (1) - source (1)
- space (1)
- space= (1)
-
space
_ before (1) -
space
_ before= (1) -
to
_ h (1) -
to
_ hash (1) -
to
_ json (21) -
to
_ json _ raw (1) -
to
_ json _ raw _ object (1)
検索結果
先頭5件
-
JSON
:: State # generate(obj) -> String (45706.0) -
Generates a valid JSON document from object obj and returns the result. If no valid JSON document can be created this method raises a GeneratorError exception.
...Generates a valid JSON document from object obj and returns the
result. If no valid JSON document can be created this method raises a
GeneratorError exception.... -
JSON
:: Generator :: GeneratorMethods :: Float # to _ json(state _ or _ hash = nil) -> String (45610.0) -
自身から生成した JSON 形式の文字列を返します。
...自身から生成した JSON 形式の文字列を返します。
@param state_or_hash 生成する JSON 形式の文字列をカスタマイズするため
に JSON::State のインスタンスか、
JSON::State.new の引数と同じ Hash を......指定します。
//emlist[例][ruby]{
require "json"
(1.0).to_json # => "1.0"
//}... -
JSON
:: Generator :: GeneratorMethods :: String # to _ json _ raw -> String (45610.0) -
自身に対して JSON::Generator::GeneratorMethods::String#to_json_raw_object を呼び出して JSON::Generator::GeneratorMethods::Hash#to_json した結果を返します。
...自身に対して JSON::Generator::GeneratorMethods::String#to_json_raw_object を呼び出して JSON::Generator::GeneratorMethods::Hash#to_json した結果を返します。
@see JSON::Generator::GeneratorMethods::String#to_json_raw_object, JSON::Generator::GeneratorMethods::Hash#to_json... -
JSON
:: Generator :: GeneratorMethods :: String # to _ json _ raw _ object -> Hash (45610.0) -
生の文字列を格納したハッシュを生成します。
... JSON に変換する場合に使用してください。
require 'json'
"にほんご".encode("euc-jp").to_json_raw_object
# => {"json_class"=>"String", "raw"=>[164, 203, 164, 219, 164, 243, 164, 180]}
"にほんご".encode("euc-jp").to_json # source sequence is illegal/malformed (JSON::Ge... -
JSON
:: State # array _ nl -> String (36646.0) -
JSON の配列の後に出力する文字列を返します。
...
JSON の配列の後に出力する文字列を返します。
//emlist[例][ruby]{
require "json"
json_state = JSON::State.new({})
json_state.array_nl # => ""
json_state = JSON::State.new(array_nl: "\n")
json_state.array_nl # => "\n"
//}... -
JSON
:: State # array _ nl=(str) (36646.0) -
JSON の配列の後に出力する文字列をセットします。
...
JSON の配列の後に出力する文字列をセットします。
//emlist[例][ruby]{
require "json"
json_state = JSON::State.new({})
json_state.array_nl # => ""
json_state.array_nl = "\n"
json_state.array_nl # => "\n"
//}... -
Class
# json _ creatable? -> bool (36610.0) -
シリアライズされた JSON 形式の文字列から、インスタンスを作成するのにこのクラスを使用できる場合は 真を返します。そうでない場合は、偽を返します。
...シリアライズされた JSON 形式の文字列から、インスタンスを作成するのにこのクラスを使用できる場合は
真を返します。そうでない場合は、偽を返します。
このメソッドが真を返すクラスは json_create というメソッドを実......装していなければなりません。
また json_create の第一引数は必要なデータを含むハッシュを期待しています。
//emlist[例][ruby]{
require "json"
String.json_creatable? # => true
Dir.json_creatable? # => false
//}... -
JSON
:: Generator :: GeneratorMethods :: Array # to _ json(state _ or _ hash = nil) -> String (36610.0) -
自身から生成した JSON 形式の文字列を返します。
...自身から生成した JSON 形式の文字列を返します。
@param state_or_hash 生成する JSON 形式の文字列をカスタマイズするため
に JSON::State のインスタンスか、
JSON::State.new の引数と同じ Hash を......指定します。
//emlist[例][ruby]{
require "json"
[1, 2, 3].to_json # => "[1,2,3]"
//}... -
JSON
:: Generator :: GeneratorMethods :: FalseClass # to _ json(state _ or _ hash = nil) -> String (36610.0) -
自身から生成した JSON 形式の文字列を返します。
...ら生成した JSON 形式の文字列を返します。
"false" という文字列を返します。
@param state_or_hash 生成する JSON 形式の文字列をカスタマイズするため
に JSON::State のインスタンスか、
JSON::State.new......の引数と同じ Hash を
指定します。
//emlist[例][ruby]{
require "json"
false.to_json # => "false"
//}... -
JSON
:: Generator :: GeneratorMethods :: Hash # to _ json(state _ or _ hash = nil) -> String (36610.0) -
自身から生成した JSON 形式の文字列を返します。
...自身から生成した JSON 形式の文字列を返します。
@param state_or_hash 生成する JSON 形式の文字列をカスタマイズするため
に JSON::State のインスタンスか、
JSON::State.new の引数と同じ Hash を......指定します。
//emlist[例][ruby]{
require "json"
person = { "name" => "tanaka", "age" => 19 }
person.to_json # => "{\"name\":\"tanaka\",\"age\":19}"
//}... -
JSON
:: Generator :: GeneratorMethods :: Integer # to _ json(state _ or _ hash = nil) -> String (36610.0) -
自身から生成した JSON 形式の文字列を返します。
...自身から生成した JSON 形式の文字列を返します。
@param state_or_hash 生成する JSON 形式の文字列をカスタマイズするため
に JSON::State のインスタンスか、
JSON::State.new の引数と同じ Hash を......指定します。
//emlist[例][ruby]{
require "json"
10.to_json # => "10"
//}... -
JSON
:: Generator :: GeneratorMethods :: NilClass # to _ json(state _ or _ hash = nil) -> String (36610.0) -
自身から生成した JSON 形式の文字列を返します。
...ら生成した JSON 形式の文字列を返します。
"null" という文字列を返します。
@param state_or_hash 生成する JSON 形式の文字列をカスタマイズするため
に JSON::State のインスタンスか、
JSON::State.new の......引数と同じ Hash を
指定します。
//emlist[例][ruby]{
require "json"
nil.to_json # => "null"
//}... -
JSON
:: Generator :: GeneratorMethods :: Object # to _ json(state _ or _ hash = nil) -> String (36610.0) -
自身を to_s で文字列にした結果を JSON 形式の文字列に変換して返します。
...した結果を JSON 形式の文字列に変換して返します。
このメソッドはあるオブジェクトに to_json メソッドが定義されていない場合に使用する
フォールバックのためのメソッドです。
@param state_or_hash 生成する JSON 形式の文字......をカスタマイズするため
に JSON::State のインスタンスか、
JSON::State.new の引数と同じ Hash を
指定します。
//emlist[例][ruby]{
require "json"
class Person
attr :name, :age
def initialize(name, ag......e)
@name, @age = name, age
end
end
tanaka = Person.new("tanaka", 29)
tanaka.to_json # => "\"#<Person:0x00007ffdec0167c8>\""
tanaka.method(:to_json).owner # => JSON::Ext::Generator::GeneratorMethods::Object
//}... -
JSON
:: Generator :: GeneratorMethods :: String # to _ json(state _ or _ hash = nil) -> String (36610.0) -
自身から生成した JSON 形式の文字列を返します。
...ら生成した JSON 形式の文字列を返します。
自身のエンコードは UTF-8 であるべきです。
"\u????" のように UTF-16 ビッグエンディアンでエンコードされた文字列を返すことがあります。
@param state_or_hash 生成する JSON 形式の文字......に JSON::State のインスタンスか、
JSON::State.new の引数と同じ Hash を
指定します。
//emlist[例][ruby]{
require "json"
puts "test".to_json # => "test"
puts '"'.to_json #......=> "\""
puts "\\".to_json # => "\\"
puts "𤘩宮城".to_json(ascii_only: true) # => "\ud851\ude29\u5bae\u57ce"
//}... -
JSON
:: Generator :: GeneratorMethods :: TrueClass # to _ json(state _ or _ hash = nil) -> String (36610.0) -
自身から生成した JSON 形式の文字列を返します。
...ら生成した JSON 形式の文字列を返します。
"true" という文字列を返します。
@param state_or_hash 生成する JSON 形式の文字列をカスタマイズするため
に JSON::State のインスタンスか、
JSON::State.new の......引数と同じ Hash を
指定します。
//emlist[例][ruby]{
require "json"
true.to_json # => "true"
//}... -
JSON
:: State # allow _ nan? -> bool (36610.0) -
NaN, Infinity, -Infinity を生成できる場合、真を返します。 そうでない場合は偽を返します。
...finity を生成できる場合、真を返します。
そうでない場合は偽を返します。
//emlist[例][ruby]{
require "json"
json_state = JSON::State.new({})
json_state.allow_nan? # => false
json_state = JSON::State.new(allow_nan: true)
json_state.allow_nan? # => true
//}
@see 4627... -
JSON
:: State # ascii _ only? -> bool (36610.0) -
ASCII 文字列のみを用いて JSON 形式の文字列を生成する場合に真を返します。 そうでない場合に偽を返します。
...ASCII 文字列のみを用いて JSON 形式の文字列を生成する場合に真を返します。
そうでない場合に偽を返します。... -
JSON
:: State # buffer _ initial _ length -> Integer (36610.0) -
This integer returns the current initial length of the buffer.
This integer returns the current initial length of the buffer. -
JSON
:: State # buffer _ initial _ length=(length) (36610.0) -
This sets the initial length of the buffer to length, if length > 0, otherwise its value isn't changed.
This sets the initial length of the buffer to length, if length > 0,
otherwise its value isn't changed. -
JSON
:: State # max _ nesting -> Integer (36610.0) -
生成される JSON 形式の文字列のネストの深さの最大値を返します。
... JSON 形式の文字列のネストの深さの最大値を返します。
この値がゼロである場合は、ネストの深さのチェックを行いません。
//emlist[例 ネストの深さチェックを行う][ruby]{
require "json"
json_state = JSON::State.new(max_nesting: 2)
json_s......# => 2
JSON.generate([[]], json_state)
JSON.generate([[[]]], json_state) # => JSON::NestingError
//}
//emlist[例 ネストの深さチェックを行わない][ruby]{
require "json"
json_state = JSON::State.new(max_nesting: 0)
json_state.max_nesting # => 0
JSON.generate([[[[[......[[[[[]]]]]]]]]], json_state)
//}... -
JSON
:: State # max _ nesting=(depth) (36610.0) -
生成される JSON 形式の文字列のネストの深さの最大値をセットします。
...生成される JSON 形式の文字列のネストの深さの最大値をセットします。
この値にゼロをセットすると、ネストの深さのチェックを行いません。
//emlist[例][ruby]{
require "json"
json_state = JSON::State.new(max_nesting: 2)
json_state.max_nestin......g # => 2
JSON.generate([[]], json_state)
json_state.max_nesting = 3
json_state.max_nesting # => 3
JSON.generate([[[[]]]], json_state) # => JSON::NestingError
//}... -
JSON
:: Parser # parse -> object (36310.0) -
現在のソースをパースして結果を Ruby のオブジェクトとして返します。
...uby のオブジェクトとして返します。
//emlist[例][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......# => Person
person.name # => "tanaka"
person.age # => 20
__END__
{
"name":"tanaka",
"age":20
}
//}
@see JSON::Parser#source... -
Range
# to _ json(*args) -> String (27625.0) -
自身を JSON 形式の文字列に変換して返します。
...自身を JSON 形式の文字列に変換して返します。
内部的にはハッシュにデータをセットしてから JSON::Generator::GeneratorMethods::Hash#to_json を呼び出しています。
@param args 引数はそのまま JSON::Generator::GeneratorMethods::Hash#to_json に渡......されます。
//emlist[例][ruby]{
require "json/add/core"
(1..5).to_json # => "{\"json_class\":\"Range\",\"a\":[1,5,false]}"
//}
@see JSON::Generator::GeneratorMethods::Hash#to_json... -
Rational
# to _ json(*args) -> String (27625.0) -
自身を JSON 形式の文字列に変換して返します。
...自身を JSON 形式の文字列に変換して返します。
内部的にはハッシュにデータをセットしてから JSON::Generator::GeneratorMethods::Hash#to_json を呼び出しています。
@param args 使用しません。
//emlist[例][ruby]{
require 'json/add/rational'
Ration......al(1, 3).to_json # => "{\"json_class\":\"Rational\",\"n\":1,\"d\":3}"
//}
@see JSON::Generator::GeneratorMethods::Hash#to_json... -
JSON
:: State # space -> String (27610.0) -
JSON 形式の文字列のトークン間に挿入する文字列を返します。
...
JSON 形式の文字列のトークン間に挿入する文字列を返します。
//emlist[例][ruby]{
require "json"
json_state = JSON::State.new(space: "")
json_state.space # => ""
puts JSON.generate([1, 2, { name: "tanaka", age: 19 }], json_state)
# => [1,2,{"name":"tanaka","age"......:19}]
json_state = JSON::State.new(space: "\t")
json_state.space # => "\t"
puts JSON.generate([1, 2, { name: "tanaka", age: 19 }], json_state)
# => [1,2,{"name": "tanaka","age": 19}]
//}... -
JSON
:: State # space=(string) (27610.0) -
JSON 形式の文字列のトークン間に挿入する文字列をセットします。
...
JSON 形式の文字列のトークン間に挿入する文字列をセットします。
@param string JSON 形式の文字列のトークン間に挿入する文字列を指定します。
//emlist[例][ruby]{
require "json"
json_state = JSON::State.new(space: "")
json_state.space......# => ""
puts JSON.generate([1, 2, { name: "tanaka", age: 19 }], json_state)
# => [1,2,{"name":"tanaka","age":19}]
json_state.space = "\t"
json_state.space # => "\t"
puts JSON.generate([1, 2, { name: "tanaka", age: 19 }], json_state)
# => [1,2,{"name": "tanaka","age": 19}]
//}... -
JSON
:: State # space _ before -> String (27610.0) -
JSON 形式の文字列中で JavaScript のオブジェクトを表す部分にある ':' の 前に挿入する文字列を返します。
...
JSON 形式の文字列中で JavaScript のオブジェクトを表す部分にある ':' の
前に挿入する文字列を返します。
//emlist[例][ruby]{
require "json"
json_state = JSON::State.new(space_before: "")
json_state.space_before # => ""
puts JSON.generate([1, 2, { n......ame: "tanaka", age: 19 }], json_state)
# => [1,2,{"name":"tanaka","age":19}]
json_state = JSON::State.new(space_before: " ")
json_state.space_before # => " "
puts JSON.generate([1, 2, { name: "tanaka", age: 19 }], json_state)
# => [1,2,{"name" :"tanaka","age" :19}]
//}... -
JSON
:: State # space _ before=(string) (27610.0) -
JSON 形式の文字列中で JavaScript のオブジェクトを表す部分にある ':' の 前に挿入する文字列をセットします。
...
JSON 形式の文字列中で JavaScript のオブジェクトを表す部分にある ':' の
前に挿入する文字列をセットします。
@param string JSON 形式の文字列中で JavaScript のオブジェクトを表す部分にある ':' の
前に挿入する文字列......uire "json"
json_state = JSON::State.new(space_before: "")
json_state.space_before # => ""
puts JSON.generate([1, 2, { name: "tanaka", age: 19 }], json_state)
# => [1,2,{"name":"tanaka","age":19}]
json_state.space_before = " "
json_state.space_before # => " "
puts JSON.gene......rate([1, 2, { name: "tanaka", age: 19 }], json_state)
# => [1,2,{"name" :"tanaka","age" :19}]
//}... -
JSON
:: State # to _ hash -> Hash (27610.0) -
自身をハッシュに変換します。
...自身をハッシュに変換します。
//emlist[例][ruby]{
require "json"
require "pp"
json_state = JSON::State.new
pp json_state.to_h
# => {:indent=>"",
# :space=>"",
# :space_before=>"",
# :object_nl=>"",
# :array_nl=>"",
# :allow_nan=>false,
# :ascii_only=>false,... -
BigDecimal
# to _ json(*args) -> String (27607.0) -
自身を JSON 形式の文字列に変換して返します。
...自身を JSON 形式の文字列に変換して返します。
内部的にはハッシュにデータをセットしてから JSON::Generator::GeneratorMethods::Hash#to_json を呼び出しています。
@param args 使用しません。
//emlist[例][ruby]{
require 'json/add/bigdecimal'
BigD......ecimal('0.123456789123456789').to_json # => "{\"json_class\":\"BigDecimal\",\"b\":\"36:0.123456789123456789e0\"}"
//}
@see JSON::Generator::GeneratorMethods::Hash#to_json... -
Date
# to _ json(*args) -> String (27607.0) -
自身を JSON 形式の文字列に変換して返します。
...自身を JSON 形式の文字列に変換して返します。
内部的にはハッシュにデータをセットしてから JSON::Generator::GeneratorMethods::Hash#to_json を呼び出しています。
@param args 引数はそのまま JSON::Generator::GeneratorMethods::Hash#to_json に渡......されます。
//emlist[例][ruby]{
require "json/add/core"
Date.today.to_json
# => "{\"json_class\":\"Date\",\"y\":2018,\"m\":12,\"d\":11,\"sg\":2299161.0}"
//}
@see JSON::Generator::GeneratorMethods::Hash#to_json... -
DateTime
# to _ json(*args) -> String (27607.0) -
自身を JSON 形式の文字列に変換して返します。
...自身を JSON 形式の文字列に変換して返します。
内部的にはハッシュにデータをセットしてから JSON::Generator::GeneratorMethods::Hash#to_json を呼び出しています。
@param args 引数はそのまま JSON::Generator::GeneratorMethods::Hash#to_json に渡......されます。
//emlist[例][ruby]{
require "json/add/core"
DateTime.now.to_json
# => "{\"json_class\":\"DateTime\",\"y\":2018,\"m\":12,\"d\":10,\"H\":1,\"M\":28,\"S\":57,\"of\":\"3/8\",\"sg\":2299161.0}"
//}
@see JSON::Generator::GeneratorMethods::Hash#to_json... -
JSON
:: State # check _ circular? -> bool (27382.0) -
循環参照のチェックを行う場合は、真を返します。 そうでない場合は偽を返します。
...y]{
require "json"
a = [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[0]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
s = JSON.state.new
begin
JSON.generate(a, s)
rescue JSON::NestingErr......or => e
[e, s.max_nesting, s.check_circular?] # => [#<JSON::NestingError: nesting of 100 is too deep>, 100, true]
end
//}
//emlist[例 ネストをチェックしないケース][ruby]{
require "json"
a = [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[......[[[[[[[[[[0]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
s2 = JSON.state.new(max_nesting: 0)
json = JSON.generate(a, s2)
[json, s2.max_nesting, s2.check_circular?] # => ["[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[... -
JSON
:: State # object _ nl -> String (27346.0) -
JSON 形式の文字列中に現れる JavaScript のオブジェクトの行末に挿入する文字列を返します。
...
JSON 形式の文字列中に現れる JavaScript のオブジェクトの行末に挿入する文字列を返します。
//emlist[例][ruby]{
require "json"
json_state = JSON::State.new(object_nl: "")
json_state.object_nl # => ""
puts JSON.generate([1, 2, { name: "tanaka", age: 19 }......], json_state)
# => [1,2,{"name":"tanaka","age":19}]
json_state = JSON::State.new(object_nl: "\n")
json_state.object_nl # => "\n"
puts JSON.generate([1, 2, { name: "tanaka", age: 19 }], json_state)
# => [1,2,{
# "name":"tanaka",
# "age":19
# }]
//}... -
JSON
:: State # object _ nl=(string) (27346.0) -
JSON 形式の文字列中に現れる JavaScript のオブジェクトの行末に挿入する文字列をセットします。
...
JSON 形式の文字列中に現れる JavaScript のオブジェクトの行末に挿入する文字列をセットします。
@param string JSON 形式の文字列中に現れる JavaScript のオブジェクトの行末に挿入する文字列を指定します。
//emlist[例][ruby]{
require......"json"
json_state = JSON::State.new(object_nl: "")
json_state.object_nl # => ""
puts JSON.generate([1, 2, { name: "tanaka", age: 19 }], json_state)
# => [1,2,{"name":"tanaka","age":19}]
json_state.object_nl = "\n"
json_state.object_nl # => "\n"
puts JSON.generate([1, 2, {......name: "tanaka", age: 19 }], json_state)
# => [1,2,{
# "name":"tanaka",
# "age":19
# }]
//}... -
JSON
:: State # configure(options = {}) -> self (27310.0) -
与えられたハッシュで自身を設定します。
...ーについては JSON::State.new を参照してください。
@param options このオブジェクトの設定をするためのハッシュを指定します。
//emlist[例][ruby]{
require "json"
json_state = JSON::State.new(indent: "\t")
json_state.indent # => "\t"
JSON.generate({key1: "va......lue1", key2: "value2"}, json_state)
# => "{\t\"key1\":\"value1\",\t\"key2\":\"value2\"}"
json_state.configure(indent: " ")
json_state.indent # => " "
JSON.generate({key1: "value1", key2: "value2"}, json_state)
# => "{ \"key1\":\"value1\", \"key2\":\"value2\"}"
//}
@see JSON::State.new... -
JSON
:: State # indent -> String (27310.0) -
インデントに使用する文字列を返します。
...インデントに使用する文字列を返します。
//emlist[例][ruby]{
require "json"
json_state = JSON::State.new(indent: "\t")
json_state.indent # => "\t"
JSON.generate({key1: "value1", key2: "value2"}, json_state)
# => "{\t\"key1\":\"value1\",\t\"key2\":\"value2\"}"
//}... -
JSON
:: State # indent=(string) (27310.0) -
インデントに使用する文字列をセットします。
...ruby]{
require "json"
json_state = JSON::State.new(indent: "\t")
json_state.indent # => "\t"
JSON.generate({key1: "value1", key2: "value2"}, json_state)
# => "{\t\"key1\":\"value1\",\t\"key2\":\"value2\"}"
json_state.indent = " "
JSON.generate({key1: "value1", key2: "value2"}, json_state)
# => "{... -
Time
# to _ json(*args) -> String (18625.0) -
自身を JSON 形式の文字列に変換して返します。
...自身を JSON 形式の文字列に変換して返します。
内部的にはハッシュにデータをセットしてから JSON::Generator::GeneratorMethods::Hash#to_json を呼び出しています。
@param args 引数はそのまま JSON::Generator::GeneratorMethods::Hash#to_json に渡......されます。
//emlist[例][ruby]{
require "json/add/core"
Time.now.to_json # => "{\"json_class\":\"Time\",\"s\":1544968675,\"n\":676167000}"
//}
@see JSON::Generator::GeneratorMethods::Hash#to_json... -
JSON
:: State # [](name) -> object (18610.0) -
Return the value returned by method name.
Return the value returned by method name. -
JSON
:: State # []=(name , value) (18610.0) -
Set the attribute name to value.
Set the attribute name to value. -
JSON
:: State # quirks _ mode=(enable) (18610.0) -
If set to true, enables the quirks_mode mode.
If set to true, enables the quirks_mode mode. -
Complex
# to _ json(*args) -> String (18607.0) -
自身を JSON 形式の文字列に変換して返します。
...自身を JSON 形式の文字列に変換して返します。
内部的にはハッシュにデータをセットしてから JSON::Generator::GeneratorMethods::Hash#to_json を呼び出しています。
@param args 使用しません。
//emlist[例][ruby]{
require 'json/add/complex'
Complex......(2, 3).to_json # => "{\"json_class\":\"Complex\",\"r\":2,\"i\":3}"
//}
@see JSON::Generator::GeneratorMethods::Hash#to_json... -
Exception
# to _ json(*args) -> String (18607.0) -
自身を JSON 形式の文字列に変換して返します。
...自身を JSON 形式の文字列に変換して返します。
内部的にはハッシュにデータをセットしてから JSON::Generator::GeneratorMethods::Hash#to_json を呼び出しています。
@param args 引数はそのまま JSON::Generator::GeneratorMethods::Hash#to_json に渡......れます。
//emlist[例][ruby]{
require "json/add/core"
begin
0/0
rescue => e
e.to_json # => "{\"json_class\":\"ZeroDivisionError\",\"m\":\"divided by 0\",\"b\":[\"/path/to/test.rb:4:in `/'\",\"/path/to/test.rb:4:in `<main>'\"]}"
end
//}
@see JSON::Generator::GeneratorMethods::Hash#to_json... -
OpenStruct
# to _ json(*args) -> String (18607.0) -
自身を JSON 形式の文字列に変換して返します。
...自身を JSON 形式の文字列に変換して返します。
内部的にはハッシュにデータをセットしてから JSON::Generator::GeneratorMethods::Hash#to_json を呼び出しています。
@param args 引数はそのまま JSON::Generator::GeneratorMethods::Hash#to_json に渡......されます。
@see JSON::Generator::GeneratorMethods::Hash#to_json... -
Regexp
# to _ json(*args) -> String (18607.0) -
自身を JSON 形式の文字列に変換して返します。
...を JSON 形式の文字列に変換して返します。
内部的にはハッシュにデータをセットしてから JSON::Generator::GeneratorMethods::Hash#to_json を呼び出しています。
@param args 引数には何の意味もありません。
//emlist[例][ruby]{
require "json/add....../core"
/0\d{1,4}-\d{1,4}-\d{4}/.to_json # => "{\"json_class\":\"Regexp\",\"o\":0,\"s\":\"0\\\\d{1,4}-\\\\d{1,4}-\\\\d{4}\"}"
//}... -
Struct
# to _ json(*args) -> String (18607.0) -
自身を JSON 形式の文字列に変換して返します。
...自身を JSON 形式の文字列に変換して返します。
内部的にはハッシュにデータをセットしてから JSON::Generator::GeneratorMethods::Hash#to_json を呼び出しています。
@param args 引数はそのまま JSON::Generator::GeneratorMethods::Hash#to_json に渡......されます。
//emlist[例][ruby]{
require "json/add/core"
Person = Struct.new(:name, :age)
Person.new("tanaka", 29).to_json # => "{\"json_class\":\"Person\",\"v\":[\"tanaka\",29]}"
//}
@see JSON::Generator::GeneratorMethods::Hash#to_json... -
Symbol
# to _ json(*args) -> String (18607.0) -
自身を JSON 形式の文字列に変換して返します。
...自身を JSON 形式の文字列に変換して返します。
内部的にはハッシュにデータをセットしてから JSON::Generator::GeneratorMethods::Hash#to_json を呼び出しています。
@param args 引数はそのまま JSON::Generator::GeneratorMethods::Hash#to_json に渡......されます。
@see JSON::Generator::GeneratorMethods::Hash#to_json... -
JSON
:: Parser # source -> String (18310.0) -
現在のソースのコピーを返します。
...現在のソースのコピーを返します。
//emlist[例][ruby]{
require 'json'
parser = JSON::Parser.new(DATA.read)
print parser.source
# => {
# => "Tanaka": {
# => "name":"tanaka",
# => "age":20
# => },
# => "Suzuki": {
# => "name":"suzuki",
# => "age":25
# => }
#... -
JSON
:: State # depth -> Integer (18310.0) -
This integer returns the current depth of data structure nesting.
This integer returns the current depth of data structure nesting. -
JSON
:: State # merge(options = {}) -> self (18310.0) -
与えられたハッシュで自身を設定します。
...ーについては JSON::State.new を参照してください。
@param options このオブジェクトの設定をするためのハッシュを指定します。
//emlist[例][ruby]{
require "json"
json_state = JSON::State.new(indent: "\t")
json_state.indent # => "\t"
JSON.generate({key1: "va......lue1", key2: "value2"}, json_state)
# => "{\t\"key1\":\"value1\",\t\"key2\":\"value2\"}"
json_state.configure(indent: " ")
json_state.indent # => " "
JSON.generate({key1: "value1", key2: "value2"}, json_state)
# => "{ \"key1\":\"value1\", \"key2\":\"value2\"}"
//}
@see JSON::State.new... -
JSON
:: State # to _ h -> Hash (18310.0) -
自身をハッシュに変換します。
...自身をハッシュに変換します。
//emlist[例][ruby]{
require "json"
require "pp"
json_state = JSON::State.new
pp json_state.to_h
# => {:indent=>"",
# :space=>"",
# :space_before=>"",
# :object_nl=>"",
# :array_nl=>"",
# :allow_nan=>false,
# :ascii_only=>false,... -
JSON
:: State # depth=(depth) (18010.0) -
This sets the maximum level of data structure nesting in the generated JSON to the integer depth, max_nesting = 0 if no maximum should be checked.
...This sets the maximum level of data structure nesting in the generated
JSON to the integer depth, max_nesting = 0 if no maximum should be
checked.... -
JSON
:: State # quirks _ mode -> bool (18010.0) -
Returns true, if quirks mode is enabled. Otherwise returns false.
Returns true, if quirks mode is enabled. Otherwise returns false. -
JSON
:: State # quirks _ mode? -> bool (18010.0) -
Returns true, if quirks mode is enabled. Otherwise returns false.
Returns true, if quirks mode is enabled. Otherwise returns false.