我在 JRuby 中有一个 Java HashMap,我正在尝试将其转换为 JSON,但它没有正确转换,我认为这个示例显示了问题:
$ irb [17:23:50]
irb(main):001:0> require 'java'
=> false
irb(main):003:0> require 'json'
=> true
irb(main):005:0> h = java.util.HashMap.new()
=> {}
irb(main):006:0> x = {}
=> {}
irb(main):007:0> JSON.parse JSON.dump x
=> {}
irb(main):008:0> JSON.parse JSON.dump h
JSON::ParserError: unexpected token at '"{}"'
from json/ext/Parser.java:251:in `parse'
from /Users/kimptoc/.rvm/rubies/jruby-1.7.3/lib/ruby/1.9/json/common.rb:155:in `parse'
from (irb):9:in `evaluate'
from org/jruby/RubyKernel.java:1066:in `eval'
from org/jruby/RubyKernel.java:1409:in `loop'
from org/jruby/RubyKernel.java:1174:in `catch'
from org/jruby/RubyKernel.java:1174:in `catch'
from /Users/kimptoc/.rvm/rubies/jruby-1.7.3/bin/irb:13:in `(root)'
irb(main):010:0> JSON.dump h
=> "\"{}\""
关于如何处理这个问题的任何想法 - 我需要将地图变成 Ruby 地图吗?
谢谢,克里斯