0
我有一个probem当我分析这样所有的文件工作解析JSON红宝石
{ “StumbleUpon公司”:0, “reddit的”:0, “脸谱”:{ “TOTAL_COUNT”:19227, “COMMENT_COUNT” :0, “SHARE_COUNT”:19227}, “LinkedIn”:27}
我的代码:
module SocialShares
class Sharedcount < Base
def shares!
response = RestClient.get(url)
JSON.parse(response)['Facebook']["share_count"] || 0
end
private
def url
"https://free.sharedcount.com/?url=#{checked_url}&apikey=#{Rails.application.secrets.socialshared_api_key}"
end
end
end
当我分析这个我有错误类型错误:字符串的隐式转换成整数
file: {“Stumb leUpon“:0,”Reddit“:0,”Facebook“:0,”LinkedIn“:0}
给出了同样的错误 –
你可以使用'dig'方法?您的数据结构高度不一致,难以使用。我已经修改了代码,让它更加偏执狂。 – tadman
感谢您的回答 –