【发布时间】:2018-01-04 16:06:15
【问题描述】:
我从对 Gmail API 的成功调用中得到以下响应:
#<Google::Apis::GmailV1::Profile:0x00007f9ad2160210 @email_address="email@example.com", @history_id=15581926, @messages_total=174760, @threads_total=127619>
但是,当我使用 awesome_print 或 pretty print 将其打印到控制台时(两者都使用 User.first 之类的测试输出预期格式),它不会将响应重新格式化为可读格式。
我试过了
ap JSON.parse(response)
我明白了
no implicit conversion of Google::Apis::GmailV1::Profile into String
我确定我不了解 API 响应的格式以及 awesome_print 的预期。有没有一种方法可以解析响应,使其在控制台中更具可读性?
【问题讨论】:
-
试试
ap response.to_h我打错了这个问题是JSON不能把它变成String -
ap response.to_h工作!谢谢!!
标签: ruby-on-rails json ruby