v2.5.2
Giriş yap

php json yazdırma

Anonim
534 defa görüntülendi ve 1 kişi tarafından değerlendirildi

böyle bir json datası var elimde ben servis1 , servis2 yazan yeri yazdırmak istiyorum ama başaramadım

{
"servis1": {
"Category": "activation",
"Qty": 2000,
"Price": 14.83
},
"servis2": {
"Category": "activation",
"Qty": 11413,
"Price": 19
}

bu benim php kodum

<?php
session_start();
include"/vendor/autoload.php";
include"/baglan.php";

//$insert =  $DB->query("INSERT INTO sc_ulke(ulke_isim) VALUES(?)", array($_POST["ulke_isim"]));
 
$ulke =  $DB->query("SELECT * FROM sc_ulke");

foreach ($ulke as $value) {

 
   $url = file_get_contents("xxxxx".trim($value["ulke_isim"])."/xxxx");
   $json = json_decode($url,true);
 
   
 print_r($json);
 
 
}
 
 ?>
asanprogrammer
953 gün önce

sanırım direkt döngü içindeki keyi almak istiyorsun ben böyle anladım onu yapmak için döngüye sokup bir arraya pushlayabilirsin keyleri
yani şöyle ;

<?php

$keys = array();

foreach($decode_json as $key => $value){
    $keys[] = $key;
}

?>

buradan çıkan sonuç sana servis1, servis2 , hepsiburada gibi yani keyde ne yazıyorsa onu döndürecektir .