用PHP处理多维JSON数组 [英] Processing Multidimensional JSON Array with PHP
问题描述
这是deepbit.net返回给我的比特币矿工的json.我正在尝试访问worker数组并循环打印myemail@gmail.com worker的统计信息.我可以访问Confirmed_reward,hashrate,ipa和payout_history,但是在格式化和输出worker数组时遇到了麻烦.
This is the json that deepbit.net returns for my Bitcoin Miner worker. I'm trying to access the workers array and loop through to print the stats for my myemail@gmail.com worker. I can access the confirmed_reward, hashrate, ipa, and payout_history, but i'm having trouble formatting and outputting the workers array.
{
"confirmed_reward":0.11895358,
"hashrate":236.66666667,
"ipa":true,
"payout_history":0.6,
"workers":
{
"myemail@gmail.com":
{
"alive":false,
"shares":20044,
"stales":51
}
}
}
谢谢您的帮助:)
推荐答案
I assume you've decoded the string you gave with json_decode method, like...
$data = json_decode($json_string, TRUE);
要访问特定工作人员的统计信息,只需使用...
To access the stats for the particular worker, just use...
$worker_stats = $data['workers']['myemail@gmail.com'];
例如,要检查它是否还活着,请选择...
To check whether it's alive, for example, you go with...
$is_alive = $worker_stats['alive'];
就是这么简单. )
这篇关于用PHP处理多维JSON数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!