nitromaster Posted July 8, 2009 Share Posted July 8, 2009 Hi I need to pass in information via a JSON to a function. The JSON array is as follows {"canvas_url":"http://www.site.com/someurl/"} Need to pass that into $facebook->api_client->admin_setAppProperties($jsonarray); where $jsonarray = that array Of course $facebook->api_client->admin_setAppProperties({"canvas_url":"http://www.site.com/someurl/"}); doesnt work. Neither does $jsonarray = '{"canvas_url":"http://www.site.com/someurl/"}'; $facebook->api_client->admin_setAppProperties($jsonarray); I've tried countless other things I could think about but still failed. What should I be looking at doing with the array? I had a look at json encode/decode as well but these seem not useful to me as I'm working with total static arrays. Thanks Link to comment https://forums.phpfreaks.com/topic/165192-passing-a-json-array-into-a-function/ Share on other sites More sharing options...
WolfRage Posted July 8, 2009 Share Posted July 8, 2009 <?php //this is not an array in PHP $jsonarray = '{"canvas_url":"http://www.site.com/someurl/"}'; //this is an array in PHP $jsonarray = array ("canvas_url"=>"http://www.site.com/someurl/"); ?> Link to comment https://forums.phpfreaks.com/topic/165192-passing-a-json-array-into-a-function/#findComment-871062 Share on other sites More sharing options...
ignace Posted July 8, 2009 Share Posted July 8, 2009 $jsonarray = json_decode('{"canvas_url":"http://www.site.com/someurl/"}'); var_dump($jsonarray); Link to comment https://forums.phpfreaks.com/topic/165192-passing-a-json-array-into-a-function/#findComment-871073 Share on other sites More sharing options...
rhodesa Posted July 8, 2009 Share Posted July 8, 2009 My guess is that the Facebook PHP Library will encode the JSON data for you. so try this: $props = array( 'canvas_url' => "http://www.site.com/someurl/", ); $facebook->api_client->admin_setAppProperties($props); Link to comment https://forums.phpfreaks.com/topic/165192-passing-a-json-array-into-a-function/#findComment-871074 Share on other sites More sharing options...
nitromaster Posted July 8, 2009 Author Share Posted July 8, 2009 My guess is that the Facebook PHP Library will encode the JSON data for you. so try this: $props = array( 'canvas_url' => "http://www.site.com/someurl/", ); $facebook->api_client->admin_setAppProperties($props); Hi Thanks for the reply, and pointing me towards what I should be doing. Yes, the facebook libary does actually enocde the data, should have read through it first Your way seems like it should work...but no matter what i seem to run into an error of something with the " => " bit when defining the array. I haven't really used arrays like so, much, recently. it's giving the following error PHP Parse error: syntax error, unexpected T_STRING in /home/mysite/set.php on line 19 Line 19 is 'canvas_url' => "http://www.site.com/someurl/", I've only been able to get other errors, when trying it some other way like PHP Parse error: syntax error, unexpected T_DOUBLE_ARROW PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING Any idea? Thanks And thanks to the rest of the repliers Link to comment https://forums.phpfreaks.com/topic/165192-passing-a-json-array-into-a-function/#findComment-871119 Share on other sites More sharing options...
WolfRage Posted July 8, 2009 Share Posted July 8, 2009 <?php //Make sure you are using the array construct especially for older versions of PHP. $props = array( 'canvas_url' => 'http://www.site.com/someurl/'); ?> Link to comment https://forums.phpfreaks.com/topic/165192-passing-a-json-array-into-a-function/#findComment-871126 Share on other sites More sharing options...
nitromaster Posted July 8, 2009 Author Share Posted July 8, 2009 <?php //Make sure you are using the array construct especially for older versions of PHP. $props = array( 'canvas_url' => 'http://www.site.com/someurl/'); ?> Still nothing. Maybe my problem lies elsewhere? PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING on that line. Might be due to my version/set of php or whatever? (although i am using php 5) Thanks Link to comment https://forums.phpfreaks.com/topic/165192-passing-a-json-array-into-a-function/#findComment-871136 Share on other sites More sharing options...
rhodesa Posted July 8, 2009 Share Posted July 8, 2009 it probably has to do something before that. can you post all the code or at least the 10 lines before the problem line. Link to comment https://forums.phpfreaks.com/topic/165192-passing-a-json-array-into-a-function/#findComment-871138 Share on other sites More sharing options...
nitromaster Posted July 8, 2009 Author Share Posted July 8, 2009 it probably has to do something before that. can you post all the code or at least the 10 lines before the problem line. Hi Full file is <? require_once 'facebook.php'; require_once 'config.php'; $bebo = new Facebook($FACEBOOK_API, $FACEBOOK_SECRET); $props = array( 'canvas_url' => 'http://www.site.com/someurl/'); $facebook->api_client->admin_setAppProperties($props); ?> Link to comment https://forums.phpfreaks.com/topic/165192-passing-a-json-array-into-a-function/#findComment-871217 Share on other sites More sharing options...
rhodesa Posted July 8, 2009 Share Posted July 8, 2009 There are no syntax errors there. Is the Parse Error you are getting in this file or one of the included files? Link to comment https://forums.phpfreaks.com/topic/165192-passing-a-json-array-into-a-function/#findComment-871244 Share on other sites More sharing options...
nitromaster Posted July 8, 2009 Author Share Posted July 8, 2009 There are no syntax errors there. Is the Parse Error you are getting in this file or one of the included files? It's in this file. To make sure it wasn't facebook.php, I changed to bebo (they have a compatible api/libary) to test first. And also removed config.php and just put the variables in this file. set.php <? require_once 'bebo.php'; $BEBO_API="YQmEbXMjdYTW38y00000000000000000000t"; $BEBO_SECRET="1lpji7Bto0jZyB6h600000000000000000000"; $bebo = new Bebo($BEBO_API, $BEBO_SECRET); $props = array( 'canvas_url' => 'http://www.mysite.com/7/'); $bebo->api_client->admin_setAppProperties($props); ?> PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/mysite/public_html/set.php on line 6 Really going over my head tbh. =/ Any ideas? Link to comment https://forums.phpfreaks.com/topic/165192-passing-a-json-array-into-a-function/#findComment-871499 Share on other sites More sharing options...
rhodesa Posted July 9, 2009 Share Posted July 9, 2009 There must be some hidden character in there. Try creating a new file and retyping it. <?php require_once 'bebo.php'; $BEBO_API="YQmEbXMjdYTW38y00000000000000000000t"; $BEBO_SECRET="1lpji7Bto0jZyB6h600000000000000000000"; $bebo = new Bebo($BEBO_API, $BEBO_SECRET); $props = array( 'canvas_url' => 'http://www.mysite.com/7/'); $bebo->api_client->admin_setAppProperties($props); ?> Link to comment https://forums.phpfreaks.com/topic/165192-passing-a-json-array-into-a-function/#findComment-872044 Share on other sites More sharing options...
haku Posted July 9, 2009 Share Posted July 9, 2009 Ya, something's odd there. It shouldn't make a difference, but you should also try using full php tags instead of the short tags. That can cause strange happenings on a server that's not configured to use them. Link to comment https://forums.phpfreaks.com/topic/165192-passing-a-json-array-into-a-function/#findComment-872076 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.