Class: Array

Inherits:
Object show all
Defined in:
lib/json/objects.rb

Direct Known Subclasses

Amazon::Coral::AwsQueryChainHelper

Instance Method Summary collapse

Instance Method Details

#from_json(lexer) ⇒ Object

This method will parse a JSON array from the passed lexer object. It takes a lexer object which is about to read a JSON array. It raises a runtime error otherwise. It returns the original JSON array. This method is not intended to be used directly. =====Parameters

lexer

Lexer object to use



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/json/objects.rb', line 122

def from_json(lexer)
  raise "A JSON Array must begin with '['" if (lexer.nextclean != "[")
  return (self) if lexer.nextclean == ']'
  lexer.back
  loop {
	self << lexer.nextvalue
	case lexer.nextclean
	when ','
	  return(self) if (lexer.nextclean == ']')
	  lexer.back
	when ']'
	  return(self)
	else
	  raise "Expected a ',' or ']'"
	end
  }
end

#to_jsonObject

This method will return a string giving the contents of the JSON array in standard JSON format.



102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/json/objects.rb', line 102

def to_json
  retval = '['

  first=true
  self.each { |obj|
	retval << ',' unless first
	retval << obj.to_json
	first=false
  }
  retval << "]"
  return(retval)
end