在PHP中从远程文件格式化多级JSON数据【已解决】

huangapple go评论56阅读模式
英文:

Formatting multilevel JSON data in PHP from remote file [SOLVED]

问题

以下是您提供的内容的翻译部分:

resc_payouts.php

{"number":1,"username":"ivalenel"},{"number":2,"username":"newb-6763"},{"number":3,"username":"jeremyhipps"},{"number":4,"username":"dcollier200"},{"number":5,"username":"AdrianEric311"},{"number":6,"username":"Prxnce24"},{"number":7,"username":"Bungy2004"},{"number":8,"username":"sevyf7"},{"number":9,"username":"jerocker79"},{"number":10,"username":"Djmoonknight8"},{"number":11,"username":"marcel_g_l"},{"number":12,"username":"zebuss"},{"number":13,"username":"fourZer0"},{"number":14,"username":"himalayabpatel"},{"number":15,"username":"Chip1234"},{"number":16,"username":"AsvpJ9k"},{"number":17,"username":"himmy23"},{"number":18,"username":"Chip1234"},{"number":19,"username":"Clares20"},{"number":20,"username":"ballermoss"},{"number":21,"username":"gareagan04"},{"number":22,"username":"cweatherfordinc"}

jsontest.php

<?php
$content = file_get_contents('https://**********.com/manage/resc_payouts.php');
$decoded_json = json_decode($content, true);

foreach($decoded_json as $key => $value) {
	$username = $decoded_json[$key]["username"];
	echo $username;
}
?>

希望这有助于您提取远程PHP文件中的JSON数据并格式化它。

英文:

I am trying to extract json data from a remote php file (not a json file) so that it each time the page is propagated it pulls the newest data to format. Here are examples of what I am trying to accomplish but I cant get it to work.

resc_payouts.php

{&quot;number&quot;:1,&quot;username&quot;:&quot;ivalenel&quot;},{&quot;number&quot;:2,&quot;username&quot;:&quot;newb-6763&quot;},{&quot;number&quot;:3,&quot;username&quot;:&quot;jeremyhipps&quot;},{&quot;number&quot;:4,&quot;username&quot;:&quot;dcollier200&quot;},{&quot;number&quot;:5,&quot;username&quot;:&quot;AdrianEric311&quot;},{&quot;number&quot;:6,&quot;username&quot;:&quot;Prxnce24&quot;},{&quot;number&quot;:7,&quot;username&quot;:&quot;Bungy2004&quot;},{&quot;number&quot;:8,&quot;username&quot;:&quot;sevyf7&quot;},{&quot;number&quot;:9,&quot;username&quot;:&quot;jerocker79&quot;},{&quot;number&quot;:10,&quot;username&quot;:&quot;Djmoonknight8&quot;},{&quot;number&quot;:11,&quot;username&quot;:&quot;marcel_g_l&quot;},{&quot;number&quot;:12,&quot;username&quot;:&quot;zebuss&quot;},{&quot;number&quot;:13,&quot;username&quot;:&quot;fourZer0&quot;},{&quot;number&quot;:14,&quot;username&quot;:&quot;himalayabpatel&quot;},{&quot;number&quot;:15,&quot;username&quot;:&quot;Chip1234&quot;},{&quot;number&quot;:16,&quot;username&quot;:&quot;AsvpJ9k&quot;},{&quot;number&quot;:17,&quot;username&quot;:&quot;himmy23&quot;},{&quot;number&quot;:18,&quot;username&quot;:&quot;Chip1234&quot;},{&quot;number&quot;:19,&quot;username&quot;:&quot;Clares20&quot;},{&quot;number&quot;:20,&quot;username&quot;:&quot;ballermoss&quot;},{&quot;number&quot;:21,&quot;username&quot;:&quot;gareagan04&quot;},{&quot;number&quot;:22,&quot;username&quot;:&quot;cweatherfordinc&quot;}

jsontest.php

&lt;?php
$content = file_get_contents(&#39;https://**********.com/manage/resc_payouts.php&#39;);
$decoded_json = json_decode($content, true);

foreach($decoded_json as $key =&gt; $value) {
	$username = $decoded_json[$key][&quot;username&quot;];
	echo $username;
}
?&gt;

I have tried many methods, converting to a string, encoding and then decoding but cant seem to figure this out. Any help on getting this remote data off a php file and formatting it would be immensely useful.

答案1

得分: 1

SOLUTION FOUND

<?php
$content = file_get_contents('https://**********.com/manage/resc_payouts.php');

$json = json_decode($content, TRUE); // decode the JSON into an associative array

foreach ($json as $key => $value) {
    echo $value['number'];
    echo $value['username'];
    echo "<br/>";
}
?>

Thanks but i figured this out myself over time

英文:

So after a few hours i found a solution

SOLUTION FOUND
&lt;?php
$content = file_get_contents(&#39;https://**********.com/manage/resc_payouts.php&#39;);

$json = json_decode($content, TRUE); // decode the JSON into an associative array

foreach ($json as $key =&gt; $value) {
	echo $value[&#39;number&#39;];
	echo $value[&#39;username&#39;];
	echo &quot;&lt;br/&gt;&quot;;
}
?&gt;

Thanks but i figured this out myself over time

huangapple
  • 本文由 发表于 2023年2月16日 17:19:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75470088.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定