Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question
If it's consistently doing that, just do a str_replace(). It's a hacky solution, but it will work. – Matt Aug 3 '12 at 14:20
But i dont think that is the good solution :) – Warrior Aug 3 '12 at 14:21
add comment (requires an account with 50 reputation)

1 Answer

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.

share|improve this answer
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 Aug 3 '12 at 14:27
@Warrior What value do you get for var_dump($params) after json_encode is performed? – Mike Brant Aug 3 '12 at 14:29
string(48) "{"radius":50,"latitude":13.35,"longitude":17.35}" – Warrior Aug 3 '12 at 14:31
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. – Mike Brant Aug 3 '12 at 14:46
In the receiving script am getting Array ( [{"radius":50,"latitude":13_35,"longitude":17_35}] => ) – Warrior Aug 3 '12 at 15:09
show 6 more commentsadd comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.