Bwizard
Bwizard

Reputation: 1023

create JSON with php

Sorry if this seems obvious but all the searches I am doing for this are returning complex answers and I have been struggling with this all day... I have been trying to create json data in PHP and really I want to send variables into the json data. I have not been able to do that so I followed a tutorial online and copied the code exactly yet i'm still not getting an output in my local host.. Please can somebody put me out of my misery...

  <?php

$jsonData = new stdClass();
$people = array(

                array(
                    'name' => 'Luci',
                     'age' => 25,
                      'sex' => 'female'
                ),
                array(
                    'name' => 'John',
                     'age' => 27,
                      'sex' => 'male')
                ),
                array(
                    'name' => 'Peter',
                     'age' =>  22,)
                      'sex' => 'male'
                )
            );



$jsonData->source = "Program Knowledge";
$jsonData->published = date('Y-m-d H:s:i;');
$jsonData->status = true;
$jsonData->people = $people;
echo json_encode($jsonData);



?>

eventually I was going to try

$var = 123456;
$jsonData->codeid = $var

but I need to figure out just how to get it so work with data I have typed in.

Many thanks..!!

Upvotes: 0

Views: 43

Answers (1)

Adam
Adam

Reputation: 56

                  'sex' => 'male')
                 'age' =>  22,)

Need to remove the parenthesis from these two lines, they're parsing errors

Upvotes: 2

Related Questions