Class: JSONServlet

Inherits:
HTTPServlet::AbstractServlet
  • Object
show all
Defined in:
lib/vendor/json_pure/tools/server.rb

Constant Summary collapse

@@count =
1

Instance Method Summary collapse

Instance Method Details

#do_GET(req, res) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/vendor/json_pure/tools/server.rb', line 12

def do_GET(req, res)
  obj = {
    "TIME" => Time.now.strftime("%FT%T"),
    "foo" => "Bär",
    "bar" => "© ≠ €!",
    'a' => 2,
    'b' => 3.141,
    'COUNT' => @@count += 1,
    'c' => 'c',
    'd' => [ 1, "b", 3.14 ],
    'e' => { 'foo' => 'bar' },
    'g' => "松本行弘",
    'h' => 1000.0,
    'i' => 0.001,
    'j' => "\xf0\xa0\x80\x81",
  }
  res.body = JSON.generate obj
  res['Content-Type'] = "application/json"
end