我试图在我的网站上显示€(数字)https://www.stratisrate.com/,但我不知道如何单独显示它并将其变成变量而不是显示整个事物。我现在有这个代码
import { MyComponent } from './MyComponents/MyComponent'
但我不知道如何只显示数字(我看过几个教程,但我仍然无法弄明白。
答案 0 :(得分:4)
您可以按照评论中的建议解析DOM,也可以使用用于通过AJAX刷新内容的JSON响应。
试试这个:
$result = json_decode(file_get_contents('https://www.stratisrate.com/json/load/rate.json'), true);
// this will print the whole array under the key 'euro'
print_r($result['euro']);
//This will get you just the value you asked for
print_r($result['euro']['rate']);
JSON响应如下所示:
{
"euro": {
"rate_title": "euro",
"rate": "3.37428419",
"strat": 0.296359,
"symbol": "€"
},
"dollar": {
"rate_title": "dollar",
"rate": "3.33987",
"strat": 0.299413,
"symbol": "$"
},
"bitcoin": {
"rate_title": "bitcoin",
"rate": "0.00163",
"strat": 613.496933,
"symbol": "Ƀ"
}
}
我通过查看Google Chrome开发工具中“网络”标签下的XHR请求找到了此信息。
然后我只是检查打开该XHR调用的url并获得结果(不需要身份验证令牌或登录)