0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

はじめに

移植やってます。
( from python 3.7 to ruby 2.7 )

json (Python)

import json

c = {'index': ['a', 'b', 'c']}
path = './test.json'
with open(path, 'w') as fp:
    json.dump(c, fp)
with open(path, 'r') as fp:
    o = json.load(fp, object_hook=dict)
    print(o)

# output
{'index': ['a', 'b', 'c']}

どうすRuby

require 'json'

c = {'index' => ['a', 'b', 'c']}
path = './test.json'
File.open(path, 'w') do |fp|
    JSON.dump(c, fp)
end
File.open(path, 'r') do |fp|
  o = JSON.load(fp)
  print(o)
end

# output
{"index"=>["a", "b", "c"]}

#test.json
{"index":["a","b","c"]}

json=>:に変換されているのが興味深いです。

メモ

  • Python の json を学習した
  • 百里を行く者は九十里を半ばとす
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?