I know this one has been asked loads of times, so mods please do not close this off as no past answers have worked and I have searched already! So I'm using the HaveIBeenPwned API which outputs what is apparently JSON like so:
[
{
"Title":"000webhost"
,"Name":"000webhost"
,"Domain":"000webhost.com"
,"BreachDate":"2015-03-01"
,"AddedDate":"2015-10-26T23:35:45Z"
,"PwnCount":12345678
,"Description":"In approximately March 2015, the free web hosting provider 000webhost suffered a major data breach that exposed over 13 million customer records. The data was sold and traded before 000webhost was alerted in October. The breach included names, email addresses and plain text passwords."
,"DataClasses":[
"Email addresses"
,"IP addresses"
,"Names"
,"Passwords"
]
,"IsVerified":true
,"IsSensitive":false
,"LogoType":"png"
}
]
That is the output if I use the following:
echo $output;
json_decode($output)
doesn't work. Using a foreach($output as $key)
doesn't work, it says invalid argument if I use that. I have tried a normal for()
loop and again no joy. What is wrong with this output? How do I get at the values within it? As you should be able to tell I'm using PHP.
$fs = json_decode($output, true);
then tryecho $fs['Title']
I just get another error: Notice: Undefined index: Title in C:\xampp\htdocs\havei\index.php on line 28 – GeordieDave1980 Nov 22 '15 at 20:56$file = file_get_contents('https://haveibeenpwned.com/api/v2/breachedaccount/foo@bar.com', false, $context); $fs = json_decode($file, true); echo $fs['Title'];
– GeordieDave1980 Nov 22 '15 at 20:58