【发布时间】:2013-12-08 06:14:49
【问题描述】:
我从 xml-rpc 服务器收到了一个这样的 json 文件:
{
"total_asr": -1,
"report": [
{
"logout_time_formatted": "2013-12-07 15:19",
"caller_id": "",
"user_id": x,
"bytes_in": "964826",
"login_time_formatted": "2013-12-07 13:46",
"details": [
[
"terminate_cause",
"Lost-Carrier"
],
[
"service",
"x"
],
[
"nas_port_type",
"Ethernet"
],
[
"mac",
"x:x:x:C6:63:DE"
],
[
"assigned_ip",
"x.x.65.139"
],
[
"port",
"x"
]
],
"ras_description": "x",
"service_type": "Internet",
"username": "x",
"successful": "t",
"bytes_out": "423928",
"before_credit": 10029.29841,
"connection_log_id": 49038,
"billed_duration": 5562,
"credit_used": 11.25756,
"retry_count": 1,
"parent_isp_credit_used": 0.0,
"duration_seconds": 5563.0,
"remote_ip": "5.200.65.139"
},
.
.
.
],
"total_rows": "85",
"total_voip_provider_credit_used": -1,
"total_credit": -1,
"total_duration": -1,
"total_out_bytes": -1.0,
"total_billed_duration": -1,
"total_in_bytes": -1.0,
"total_acd": -1
}
我想获得一些领域: 结果 = {}
rpc = IbsXmlRpc.new
res = rpc.getConnectionLogs("200")
result = res["report"].map{|key|
{
"duration" => (key["duration_seconds"].to_i/60).to_s,
"bytes_in" => (key["bytes_in"].to_i/1024).to_s,
"bytes_out" => (key["bytes_out"].to_i/1024).to_s,
}
}
到目前为止一切正常,但是当我要获取 json 的最后一个字段时:
result["total_duration"] = res["total_duration"].to_s
result["total_out_bytes"] = res["total_out_bytes"].to_s
result["total_in_bytes"] = res["total_in_bytes"].to_s
我收到此错误:no implicit conversion of String into Integer
我真的不知道发生了什么,并测试了我所知道的一切。知道为什么会这样吗?
【问题讨论】:
标签: ruby-on-rails json