Pregunta

This is the object that is being returned.

Object: 
    contributors_enabled: false
    created_at: "Sat Apr 18 02:20:51 +0000 2009"
    ...
    status: Object
    ...
    verified: false

As you can see there are 2 objects. The parent and then the object inside that called "status".

In javascript, how does one go about accessing the "status" object.

I have tried object.status which returns null.

Real Code:

function get_data( $id ) { 
    global $tmhOAuth; 
    $code = $tmhOAuth->request( 'POST', $tmhOAuth->url('1/users/lookup.json', ''), array( 'user_id' => $id ) );
    if ( $code == 200 ) {
        $data = json_decode($tmhOAuth->response['response'], true);
        return $data; 
    } else { 
        outputError($tmhOAuth);
    }   
} 

if ( !empty( $_POST ) && !is_null( $_POST ) ) { 
    extract( $_POST ); //imports $id; 
    $data = get_data($id); 
    exit(json_encode($data)); 
} 


$.post( 
    '/twitauth/app.php', 
    data, 
    function( response ) { 
        console.log( response ); 
    }, 
   'json'
); 
¿Fue útil?

Solución

You will need to post the actual code, because either of these two should work:

object.status
object["status"]

If those aren't working, then you have defined the object incorrectly somehow, or the object within the object is private.

Otros consejos

You can reference n layers of objects using the . operator, no problem.

Here's an example

var myobj = {
    'a' : 1,
    'b' : 2
};

var foobar = {
    'foo' : 'bar',
    'status' : myobj    
    };

console.log(foobar.status.a);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top