29 lines
1.2 KiB
PHP
29 lines
1.2 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../config.php';
|
|
|
|
echo "<h2>Test JSON Decode</h2>";
|
|
|
|
// Test dengan data yang kita tahu benar
|
|
$test_json = '{"status":1,"pesan":"","data":[{"id_berita":"13","tanggal":"2025-06-03","photo":"bc48a-libur-idul-adha-2025.jpg","judul":"Libur Nasional Idul Adha","isi":"<p>Pemberitahuan Libur Idul Adha tanggal 6 Juni 2025 dan Cuti Bersama Tanggal 9 Juni 2025.<\/p><p>Operasional Kembali Pada Tanggal 10 Juni 2025<\/p>"}]}';
|
|
|
|
echo "<h3>Raw JSON:</h3>";
|
|
echo "<pre>" . $test_json . "</pre>";
|
|
|
|
$decoded = json_decode($test_json, true);
|
|
echo "<h3>Decoded Array:</h3>";
|
|
echo "<pre>" . print_r($decoded, true) . "</pre>";
|
|
|
|
echo "<h3>Access Data:</h3>";
|
|
echo "Status: " . ($decoded['status'] ?? 'N/A') . "<br>";
|
|
echo "Data Count: " . (isset($decoded['data']) ? count($decoded['data']) : 'N/A') . "<br>";
|
|
|
|
if (isset($decoded['data']) && is_array($decoded['data'])) {
|
|
$first_item = $decoded['data'][0];
|
|
echo "First Item Judul: " . ($first_item['judul'] ?? 'N/A') . "<br>";
|
|
echo "First Item Tanggal: " . ($first_item['tanggal'] ?? 'N/A') . "<br>";
|
|
echo "First Item Isi: " . substr(strip_tags($first_item['isi'] ?? 'N/A'), 0, 100) . "...<br>";
|
|
}
|
|
|
|
echo "<h3>JSON Error:</h3>";
|
|
echo "JSON Last Error: " . json_last_error_msg() . "<br>";
|