I am making a cheat detecting small software piece for personal use in PHP, the code scans all files in a directory, sorts out all of the .JSON
files and then will parse and return some values. I have one function working to tell me what the version number is from the JSON
file:
function scan_Versions($dir) {
$array = array();
$rdi = new RecursiveDirectoryIterator($dir);
foreach (new RecursiveIteratorIterator($rdi) as $filename => $file) {
if(!is_dir($filename)) {
$path_parts = pathinfo($filename);
$ext = $path_parts["extension"]. PHP_EOL;
if (strpos($ext, "json") !== false) {
$str = file_get_contents($filename);
$json = json_decode(utf8_decode($str), true);
array_push($array,$json['id']);
}
}
}
return $array;
}
When executed it will scan the files, and get data from a JSON
file like this: http://pastebin.com/3VdEZW43 (It gets the first id
part of the JSON
)
I need a function like the one above to retrieve the data from:
"libraries": [
{
"name": "oshi-project:oshi-core:1.1", <----- I NEED THIS!!!!!!!!!!
"downloads": {
"artifact": {
"url": "https://libraries.[REMOVED].net/oshi-project/oshi-core/1.1/oshi-core-1.1.jar",
"sha1": "9ddf7b048a8d701be231c0f4f95fd986198fd2d8",
"size": 30973
}
}
}.......
From the "name":
that contains: oshi-project:oshi-core:1.1
. Can someone help me do this?
I don't have enough rep to add a comment (new here), but you would want
$json["libraries"][0]["name"]
not
$json["libraries"]["name"][0]
according to the pastebin link.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.