国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Ruby - Convert nested objects to json?
僅有的幸福
僅有的幸福 2017-06-08 11:02:01
0
1
1494

How to convert nested objects to json in ruby?
For example, an object obj contains a custom instance variable b
If you use to_json, the content of b cannot be output.
What is needed is the output of obj.to_s, but if it is in the form of json
It is possible to use to_yaml, but I hope to convert it directly to json

By the way, to_json and to_yaml are obviously the same function. Why is there such a difference in results?

僅有的幸福
僅有的幸福

reply all(1)
扔個(gè)三星炸死你
require 'oj'

class A
    def initialize a=[1,2,3], b='hello'
        @a = a
        @b = b
    end
end
puts Oj::dump a, :indent => 2, :mode => :compat

Output:

{
  "a":[
    1,
    2,
    3
  ],
  "b":"hello"
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template