0

嗨,我正在将 JSON 数据转换为字符串。请在下面找到 JSON 数据。我面临一个问题,即系统中无法将 NULL 值转换为字符串。因此,我收到以下错误:can't convert nil into String (TypeError)

JSON数据:

{"success":true,"message":null,"data":null}

使用的代码:

c = Curl::Easy.new(Configuration.fetch("<URL where we can find the above JSON DATA and nothing else>"))
#    c.follow_location = true
#    c.http_auth_types = :basic
#    c.username = Configuration.fetch('auth_user', false)
#    c.password = Configuration.fetch('auth_pass', false)
#    c.headers["User-Agent"] = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17'
#    c.perform
     result=JSON.parse(c)
     puts result["Success"]

请帮忙。

4

1 回答 1

1

尝试

puts result["success"]

你有一个大写的 S,你需要一个小写的。

于 2013-10-18T03:52:02.137 回答