PHP解析Json API页面中的一行
我试图将这个脚本从查找一组变量(例如playtime\u forever)转换为查找另一个变量(backack\u value)PHP解析Json API页面中的一行,php,json,api,parsing,Php,Json,Api,Parsing,我试图将这个脚本从查找一组变量(例如playtime\u forever)转换为查找另一个变量(backack\u value) 一个小的改变,但我无法使脚本做我想要的。如果你能解释一下怎么做,以及背后的步骤,那就太好了。我已经尝试了一段时间,但无法完成脚本要根据您的评论获取配置文件,请使用以下代码: $profiles = array(); //init array so we can use $profiles[] later $limitValue = 1000; //Limit val
一个小的改变,但我无法使脚本做我想要的。如果你能解释一下怎么做,以及背后的步骤,那就太好了。我已经尝试了一段时间,但无法完成脚本要根据您的评论获取配置文件,请使用以下代码:
$profiles = array(); //init array so we can use $profiles[] later
$limitValue = 1000; //Limit value of backpack_value
foreach($data->response->players as $player) { // Loop thrugh all the players
if ($player->backpack_value < $limitValue) { // Check the backpack_value
$profiles[] = $player; // Assign the required players to a new array
}
}
var_dump($profiles); // Dump the array to browser for debugning
$profiles=array()//初始化数组,以便稍后使用$profiles[]
$limitValue=1000//背包的极限值
foreach($data->response->players as$player){//遍历所有玩家
如果($player->backpack\u value<$limitValue){//检查backpack\u值
$profiles[]=$player;//将所需的玩家分配到新阵列
}
}
变量转储($profiles);//将阵列转储到浏览器以进行调试
这两个JSON文件完全不同。新JSON没有旧JSON的任何键。您甚至试图以什么方式从新的JSON中检索哪些数据?上面的完整代码如下。我希望这个新脚本能够解析出“backpack_value”小于一定数量的配置文件。请相应地更新您的问题,使其更清晰易读。我实现了它,它没有输出任何内容。有什么建议吗?(这是unique.txt的内容)我要把它弄乱了,但也许你注意到了一些我没注意到的问题。如果(!empty($data->backpack_value)){因为$data->backpack_value
不存在,你应该尝试如果(!empty($data))
或者如果($data->响应->成功))
修复了它,效果非常好。唯一的问题是我试图找到一个最小值而不是最大值的东西。如果($player->backpack_值<99999)和($player->backpack_值>50)){但它不起作用,我需要更多更改吗?你需要类似于的东西,如果($player->backpack_值>$lowerLimit)&&($player->backpack_value<$higherLimit)){
仔细查看后,所有脚本现在都会输出第一个链接,不管结果如何。。。
{
"response": {
"success": 1,
"current_time": 1369669066,
"players": {
"0": {
"steamid": "76561197992146126",
"success": 1,
"backpack_value": 36412.71,
"backpack_update": 1369630863,
"name": ":HIT: Bobo the Monkey Boy",
"notifications": 0
}
}
}
}
$profiles = array(); //init array so we can use $profiles[] later
$limitValue = 1000; //Limit value of backpack_value
foreach($data->response->players as $player) { // Loop thrugh all the players
if ($player->backpack_value < $limitValue) { // Check the backpack_value
$profiles[] = $player; // Assign the required players to a new array
}
}
var_dump($profiles); // Dump the array to browser for debugning