gpt4 book ai didi

ruby - 遍历 json 数组并检索一个属性,也给出错误

转载 作者:数据小太阳 更新时间:2023-10-29 08:03:18 25 4
gpt4 key购买 nike

我是 ruby​​ 编程的新手,我正在尝试获取 json['earning_rate_hr'] 的值,但我收到一个错误,in '[]': no implicit将字符串转换为整数(TypeError)
我知道并理解错误,但这不是我的主要问题,这里是我的文件:
检查检查器.rb :

#require_relative '../lib/hackex/net/typhoeus'
require_relative '../lib/hackex'
require 'rubygems'
require 'json'

file = 'accounts1.txt'
f = File.open file, 'r'
puts "MADE BY THE PEOPLE, FOR THE PEOPLE #madebylorax"
puts ""
puts "--------------------------------------------------------"
puts ""

while line = f.gets
line = line.chomp.split(';')
email, password = line
puts "logging in as " + email
HackEx.LoginDo(email, password) do |http, auth_token, user|
puts "getting info..."
user = HackEx::Request.Do(http, HackEx::Request.UserInfo(auth_token))['user']
puts "receieved user info!"
bank = HackEx::Request.Do(http, HackEx::Request.UserBank(auth_token))['user_bank']
puts "recieved bank info!"
json = HackEx::Request.Do(http, HackEx::Request.UserSpam(auth_token))['spam']
puts "recieved spam info!"
puts json['earning_rate_hr'] #error line, the error is because this is an array, and it cant be turned into integer, i was wondering if there is a way to use puts on it without trying to make it an integer
userchecking = bank["checking"]
checking = userchecking.scan(/.{1,3}/).join(',')
puts email + " has in Checking: BTC #{checking}"
puts ""
puts "--------------------------------------------------------"
puts ""
end
end

我试着做 puts json,它会放像这样的项目:

{"id"=>"9867351", "user_id"=>"289108", "victim_user_id"=>"1512021", "victim_ip"= "86.60.226.175", "spam_level"=>"50", "earning_rate_hr"=>"24300", "total_earning s"=>"13267800", "started_at"=>"2015-11-01 07:46:59", "last_collected_at"=>"2015- 11-24 01:46:59"}

我想做的是为每个选择 earning_rate_hr 并将它们加在一起,但是我不知道如何做,因为错误没有修复,我无法得到它的值< br/>ps:我试过把它变成Hash,我也试过用.first,但是.first只显示第一个,我想显示所有的,谢谢

最佳答案

我从 line messenger 认识你,我已经很长时间没有使用 ruby​​ 代码了,这个代码一直给我 cloudflare 错误,我不确定是不是因为服务器停机/维护或其他原因,但无论如何,这是你的脚本,享受耕作 ;) -LineOne

PS,我更改了一些字符串,使它看起来更干净,这样您可以更容易地看到垃圾邮件收入,并添加了 sleep (1),因为在重新连接之前 sleep 一秒钟有助于防止 cloudflare 错误你也不需要在你的 hackex 脚本中要求 json 或 ruby​​gems,因为它在库中是必需的,所以它的所有内容都涵盖了预用户输入/脚本

require_relative 'libv5/lib/hackex'
while 1<2
begin
print'Filename: '
fn=gets.chomp
file = fn+'.txt'
f = File.open file, 'r'
puts "MADE BY THE PEOPLE, FOR THE PEOPLE #madebylorax" #helped by lineone
puts ""
puts "--------------------------------------------------------"
puts ""

while line = f.gets
line = line.chomp.split(';')
email, password = line
HackEx.LoginDo(email, password) do |http, auth_token, user|
puts "Retrieving Info..."
puts''
user = HackEx::Request.Do(http, HackEx::Request.UserInfo(auth_token))['user']
bank = HackEx::Request.Do(http, HackEx::Request.UserBank(auth_token))['user_bank']
json = HackEx::Request.Do(http, HackEx::Request.UserSpam(auth_token))['spam']
cash_count=0
tot_count=0
json.each do |j|
earn_rate = j['earning_rate_hr']
total= j['total_earnings']
cash_count+=earn_rate.to_i
tot_count+=total.to_i
end
print "#{email}: current earnings: #{cash_count} per hour, Total earnings #{tot_count},"
userchecking = bank["checking"]
checking = userchecking.scan(/.{1,3}/).join(',')
puts " #{checking} BTC in Checking"
puts ""
puts "--------------------------------------------------------"
puts ""
sleep 1
end
end
rescue
puts"#{$!}"
end
end

关于ruby - 遍历 json 数组并检索一个属性,也给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33889403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com