【问题标题】:Convert JSON data into String将 JSON 数据转换为字符串
【发布时间】:2013-10-26 19:06:30
【问题描述】:

您好,我正在将 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"]

请帮忙。

【问题讨论】:

  • 向我们展示您当前产生错误的尝试。
  • 我已经编辑了这个问题。希望您现在可以看到代码。

标签: ruby json


【解决方案1】:

试试

puts result["success"]

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

【讨论】:

  • 感谢您的回复。但我的努力失败了。我收到一个新错误“无法将 Curl::Easy 转换为 String (TypeError)。”
  • 您可以先尝试在 IRB 会话中编辑您的代码。它会在每一步之后告诉您,它对您输入的内容有何影响。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-11-19
  • 1970-01-01
  • 1970-01-01
  • 2018-06-28
  • 2020-04-27
  • 2013-03-14
  • 1970-01-01
相关资源
最近更新 更多