-2

I have an answer in json, but how can I parse?

Response: (var_dump)

C:\wamp64\www\PHP\index.php:17:
object(stdClass)[1]
  public 'success' => boolean true
  public 'data' => 
    array (size=1)
      0 => 
        object(stdClass)[2]
          public 'key' => string '11111-11111-11111-11111-11111' (length=29)
          public 'allowed_acts' => int 1

I tried this code, but dont works

if ($keys) {

$json = json_decode($keys);

//$dump = var_dump($json);

//echo $dump;

echo $json['key'];
}

Fatal error: Cannot use object of type stdClass as array in C:\wamp64\www\PHP\index.php on line 21

Ken Soares
  • 57
  • 1
  • 4

1 Answers1

1

You have already parsed response. Please note that in your response var_dump result you have

object(stdClass)[1]

which means it's already na object.

You can access its content with -> operator.

E.g. to get key value, you should try with:

echo $result->data[0]->key;
Jakub Matczak
  • 15,341
  • 5
  • 46
  • 64