0

im new to json, I have the below code that works, my problem is the address field has 9 fields in it, anyone know how I can get parts of the address from $candidate->address e.g.

$address1 = '110 Middlesex Street'
$city = 'London'
$zip = 'E1 7HY'

-- my code -- '''

Candidate: '.$candidate->firstName.' '.$candidate->lastName.'

Email: '.$candidate->email.'

Address: '.print_r ($candidate->address).'

'''

Output on the web page...

</head>
<body>stdClass Object
(
    [address1] => 110 Middlesex Street
    [address2] => 
    [city] => London
    [countryCode] => UK
    [countryID] => 2359
    [countryName] => United Kingdom
    [state] => Greater London
    [timezone] => 
    [zip] => E1 7HY
)
<div class="" style="">
    <p>Name: <span class="">David Kyloe</span></p>
    <p>Email: <span class="">me@home.co.uk</span></p>
    <p>Address: <span class="">1</span></p>
            
</html>

I have been trying loads of examples on-line, sadly I can't get them to work, the last example I found that's still not working is:

$json = $candidate->address;

$json = json_decode($json,true);
foreach ($json as $ad) {
    if ($ad['city'] == $city) {
        echo $ad;
    }
}

Thanks in advance.

  • Too bad they closed it. I know how to make it very easy. This past weekend I scraped realest listings from Zillow and realtor.com. That would be a nightmare if I didn't have the tools I made. I wrote an app to parse the JSON and it gives the exact PHP variable you need for every element in the JSON. The JSON I extracted for the web page was was over 100,000 bytes for each page. Here an example, all I had to do was copy the variable. $json['cat1']['searchResults']['listResults'][0]['addressStreet'] – Misunderstood Aug 26 '22 at 23:20
  • Here is a Zillow JSON file: http://ispeedlink.com/jsn/zillow.jsn It's nearly impossible to decipher. This next link read in the same JSON and gives you lots of deatils. http://ispeedlink.com/jsn/json.php?f=http://ispeedlink.com/jsn/zillow.jsn – Misunderstood Aug 27 '22 at 00:55

0 Answers0