我正在考虑编写一个 Web 应用程序来抓取 API 并以 JSON 形式返回此信息。
但是,我只关注一个数字,然后是当前价格(在本示例中为“227”)。我如何在 Ruby 中访问它?我不知道从哪里开始。我从来没有处理过这样的文字。
为了讨论的目的,假设我将此输出保存到实例变量中@information
{
"item": {
"icon": "http://services.runescape.com/m=itemdb_rs/4332_obj_sprite.gif?id=4798",
"icon_large": "http://services.runescape.com/m=itemdb_rs/4332_obj_big.gif?id=4798",
"id": 4798,
"type": "Ammo",
"typeIcon": "http://www.runescape.com/img/categories/Ammo",
"name": "Adamant brutal",
"description": "Blunt adamantite arrow...ouch",
"current": {
"trend": "neutral",
"price": 227
},
"today": {
"trend": "neutral",
"price": 0
},
"day30": {
"trend": "positive",
"change": "+1.0%"
},
"day90": {
"trend": "positive",
"change": "+1.0%"
},
"day180": {
"trend": "positive",
"change": "+2.0%"
},
"members": "true"
}
}