php object question
- Started
- Last post
- 5 Responses
- n8w
I am trying to get part of an object into a variable .. but I am not sure how to access it
this doesn't seem to work??print $obj->results['shortUrl'];
how can I do this?
$myvar="http://bit.ly/e4miJ";(I want to extract this part of the object)
thanks!!!!!!!!!Code: [Select]
<? $json = '{ "errorCode": 0, "errorMessage": "", "results": { "http://www.n8w.com/image/art/witchcraft/": { "hash": "IB0iS", "shortKeywordUrl": "", "shortUrl": "http://bit.ly/e4miJ", "userHash": "e4miJ" } }, "statusCode": "OK" }'; $obj = json_decode($json); print $obj->results['shortUrl'];
- ********0
man, I'm not a nerd, I'm just a troll
- ********0
i dont see clearly your context, but it is easy, use json decode function
http://fr3.php.net/manual/en/fun…
pass a true parameter so you get an associative array, done.- I'm just a troll********
- o_Odropdown
- i know it********
- ok - the libios delete my thread!********
- I'm just a troll
- neverblink0
do a print_r($obj) to see what the content of the array is..
- n8w0
thanks for the help ..
I know whats in the object .. I just can't seem to figure out the syntax to get the variable I need .. it's an object within an objectprint $obj->{'errorCode'};
this prints "0"but what I need is
print $obj->{'results.child.child.shor...
which should print "http://bit.ly/e4miJ"
- neverblink0
$obj->results->shortUrl ?