Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
Load JSON File and print specific Parts

im building a simple webpage for school. Sadly ive got several problem. Im using an Apache Webserver with XAMPP.

I got a JSON-File like:

{
    
"lose":[
{
    "Zustand":"geschlossen",
    "Losnummer":1,
    "Gewinnklasse":"A",
    "Preis":10
},

{
    "Zustand":"geschlossen",
    "Losnummer":2,
    "Gewinnklasse":"B",
    "Preis":20
},

This file is on my Webserver too. I want to load this file especially with XHTML Request and then want to print several parts of this JSON File into HTML/PHP Code. I watched a lot of youtube videos but i dont get a way that works for me. I managed to load the JSON-File via XHTML and im able to print it in HTML, but it is always the whole JSON in the so called "responseText" and this is basically a large String for me. Im fairly new in this stuff so sorry if i mess things up.

So TLDR: load JSON file in webpage, print single parts of it in several HTML div tags. Im allowed to use html,php,js.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Something like this:

<?php 
$json = 
'
{
    "lose": [
    {
        "Zustand":"geschlossen",
        "Losnummer":1,
        "Gewinnklasse":"A",
        "Preis":10
    },
    {
        "Zustand":"geschlossen",
        "Losnummer":2,
        "Gewinnklasse":"B",
        "Preis":20
    }]
}
';

$arr = json_decode($json, true);
echo "<table border='1'>";
foreach($arr["lose"] as $single) {
    echo "<tr>";
    echo "<td>".$single['Zustand']."</td>";
    echo "<td>".$single['Losnummer']."</td>";
    echo "</tr>";
}
echo "</table>";
about 4 years ago · Juan Pablo Isaza Report

0

In JS, you can use the built-in JSON.parse() method.

https://www.w3schools.com/Js/js_json_parse.asp

You can then access individual elements in that data structure as first class citizens.

Using your example, here's a minimum working example:

let dataString = ` 
{
    "lose":[
        {
            "Zustand":"geschlossen",
            "Losnummer":1,
            "Gewinnklasse":"A",
            "Preis":10
        },    
        {
            "Zustand":"geschlossen",
            "Losnummer":2,
            "Gewinnklasse":"B",
            "Preis":20
        }
    ]
}
`

let data = JSON.parse(dataString);


// If we log out data, it will simply print everything
console.log(data);

// This will access the first element of the array
console.log(data.lose[0]); 

// To iterate through the entire 'LOSE' array
data.lose.forEach(element => {
    // Since we're in the middle of the array, we can now access individual properties
    console.log(element.Zustand);
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!