1

I have created a oauth api in php using this example

http://code.google.com/p/oauth-php/wiki/ConsumerHowTo#OAuth_Consumer

And in the consumer page i am passing the params as json encoded string.

$key = '35345345345vertrtertert'; // fill with your public key 
$secret = 'h rtyrtyr767567567567'; // fill with your secret key
$url = "www.server.com/serverurl.php"; 

$options = array('consumer_key' => $key, 'consumer_secret' => $secret);
OAuthStore::instance("2Leg", $options);

$method = "POST";
$params = array(
           'radius' => '50',
           'latitude'=>'13.35',
           'longitude'=>'17.35'
     );
$params = json_encode($params);

And in the server page(ie serverurl.php) am printing the request using

print_r($_REQUEST);

And i decoded the string using json decode, but am getting this value as

    Array
(
    [radius] => 50
    [latitude] => 13_35
    [longitude] => 17_35
)

The . is replaced with _ in latitude and longitude How i can manage this

2
  • If it's consistently doing that, just do a str_replace(). It's a hacky solution, but it will work. Commented Aug 3, 2012 at 14:20
  • But i dont think that is the good solution :) Commented Aug 3, 2012 at 14:21

1 Answer 1

1

It seems that somewhere along the line in your encoding/decoding process the value is trying to be parsed a a number of something. If you truly want to work with these values as numbers, you shouldn;t set themn in your array as strings. Try this

$params = array(
    'radius' => 50,
    'latitude'=> 13.35,
    'longitude'=> 17.35
);

Note that I have removed the quotes around the numbers so they will be treated as numbers in the encoding process.

Sign up to request clarification or add additional context in comments.

8 Comments

If i remove the quotes, foreach($_REQUEST as $key=>$value) { $array_val = $key; } $decode_val= json_decode($array_val,true); print_r($decode_val); this code print nothing
@Warrior What value do you get for var_dump($params) after json_encode is performed?
string(48) "{"radius":50,"latitude":13.35,"longitude":17.35}"
And is that string intact in the raw $_POST variable in the receiving script? It might help to show the script you are posting to.
In the receiving script am getting Array ( [{"radius":50,"latitude":13_35,"longitude":17_35}] => )
|

Your Answer

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.