0

I run into a problem, since I'm new to JSON parse in PHP...

I get the following response when calling to an api, after successful login:

{
 "result": true,
 "errors": [],
 "response": {
 "result": true,
 "count": 1,
 "more": false,
 "azafatas": [
 {
 "serverDeleted": false,
 "tstamp": "000000ff56937c7",
 "idAzafata": 3f332,
 "nombre": "Teresa",
 "apellidos": "L",
 "agencia": {
 "serverDeleted": false,
 "tstamp": "000ff000000071949d",
 "idAgencia": f1076,
 "nombre": "Agency",
 "codigo": "",
 "descripcion": "",
 "email": "[email protected]",
 "telefono": "+351 912145003"
 },
 "idAgencia": 1076,
 "alias": "Teresa L",
 "codigo": "084",
 "email": "[email protected]",
 "telefono": "9163449236",
 "direccion": {
 "serverDeleted": false,
 "tstamp": "000000d540000718157",
 "idDireccion": 66573,
 "idProvincia": 1160,
 "direccionCompleta": "Mimosa n 20",
 "posicion": {
 "longitude": -8.057900000008,
 "latitude": 42.2104936
 },
 "provincia": {
 "serverDeleted": false,
 "tstamp": "00009809000520a4f9",
 "idProvincia": 1160,
 "nombre": "PORTO",
 "codigo": "PORTO"
 },
 "codigoPostal": "4585-359",
 "descripcion": "",
 "localidad": "Paredes",
 "posicionVerificada": true
 }
 }
 ]
 }
}

I need to get the value of "nombre": "Teresa" inside a $variable.

I tryed echo $json['response']['azafatas']['nombre']; but I get "Notice: Undefined index: nombre in..."

But if I try echo $json['response']['result']; I get correct echo "1"

What I'm missing to get the value of nombre...

Best regards!

asked Dec 4, 2015 at 16:31

1 Answer 1

1

try :

$json['response']['azafatas'][0]['nombre'];

on azafatas you will see mark '[' its means the json using index like usual array...

answered Dec 4, 2015 at 16:40
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.