0

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.

0

1 Answer 1

1

Use json_decode($output, true);

Second parameter defines result data format - object (false, default) or associated array (true).

Sign up to request clarification or add additional context in comments.

10 Comments

Nope am afraid I just get - Notice: Array to string conversion in C:\xampp\htdocs\havei\index.php on line 27. I used what you told me to, there is some kind of an issue with it, just doesn't seem to want to output it.
So for example if I use <code>$fs = json_decode($output, true);</code> then try <code>echo $fs['Title']</code> I just get another error: Notice: Undefined index: Title in C:\xampp\htdocs\havei\index.php on line 28
Update your question with your code example, so we could answer your question
Ok, what if print_r($fs); ?
I think you need $fs[0]['Title']; in you case, because your json string starts with [
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.