2016-04-25 20 views
0

Wepay payment gatewayを統合しました。しかし、私はjson object to wepayを渡す問題に直面している。常に不正なjson形式を表示します。以下のコードを見てください。Wepay APIでPHPを使用してjsonオブジェクトを渡す方法

$forca_a = array(
    'debit_opt_in'=>true 
); 
$forca = json_encode($forca_a,JSON_FORCE_OBJECT); 
$wepay_create_array = array(
    'name' =>"xxxx", 
    'description' => "xxxxxxxxx xxxx", 
    'callback_uri' => "xxxxxxx", 
    'country' => "CA", 
    'currencies' => array('CAD'), 
    'country_options' => $forca, 
    'rbits'=> array(
       array(
        'receive_time'=>strtotime("now"), 
        'type' =>'website_uri', 
        'source' => 'partner_database', 
        'properties'=> array('uri'=>xxxxx) 
       ) 
      ) 
); 

私はcountry_optionsに合格しない場合は、その作業には思われるが、私は、このパラメータを渡すと、それは常に私にエラーを与えるには、「不正なJSON形式」と言います。

私はウェイペイヘルプセンターにメールを送りました。彼らは"country_options":"{"debit_opt_in":true}" <--- this is a stringの代わりに"country_options":{"debit_opt_in":true} <--- this is a JSON objectの文字列を渡していると言いました。だから私は混乱している。どのようにJSONオブジェクトを渡すのか分かりません。唯一の道があり、json_encode($object)です。あなたが置く前に

$forca = json_encode($forca_a,JSON_FORCE_OBJECT); 

答えて

0

ちょっとこのコードは次のようなJSON出力に

{ 
     "name": "xxxx", 
     "description": "xxxxxxxxx xxxx", 
     "callback_uri": "xxxxxxx", 
     "country": "CA", 
     "currencies": ["CAD"], 
     "country_options": { 
      "debit_opt_in": true 
     }, 
     "rbits": [{ 
      "receive_time": 1461561030, 
      "type": "website_uri", 
      "source": "partner_database", 
      "properties": { 
       "uri": "xxxxx" 
      } 
     }] 
    } 
+0

https://www.wepay.com/developer/reference/account#createこのリンクを見てください。私は、配列全体ではなく、「country_options」をjsonオブジェクトに渡す必要があります。 –

+0

あなたは私が望んでいるjson形式を教えてください。 –

+0

実際にそれを今修正しました。上記の答えに私のコメントを見てください。 –

0

を与えるあなたが作る必要がない、適切なJSONを取得するためのコードの下に

<?php 
$forca_a = array(
        'debit_opt_in'=>true 
      ); 
    // $forca = json_encode($forca_a); 
    $wepay_create_array = array(
        'name' =>"xxxx", 
        'description' => "xxxxxxxxx xxxx", 
        'callback_uri' => "xxxxxxx", 
        'country' => "CA", 
        'currencies' => array('CAD'), 
        'country_options' => $forca_a, 
        'rbits'=> array(
           array(
            'receive_time'=>strtotime("now"), 
            'type' =>'website_uri', 
            'source' => 'partner_database', 
            'properties'=> array('uri'=>'xxxxx') 
           ) 
          ) 
       ); 


print_r(json_encode($wepay_create_array)); 
        ?> 

を使用$ wepay_create_arrayに渡します。 リクエストを送信する前に、を作成してください。その後、country_optionsキーに 'string'が表示されます。

+0

https://www.wepay.com/developer/reference/account#createこのリンクを見てください。私は、配列全体ではなく、「country_options」をjsonオブジェクトに渡す必要があります。 –

+0

この回答のjsonObjectとjsonArrayの違いを参照してください。http://stackoverflow.com/a/16145788/5686207 json_encode($ forca)はメインリクエスト配列に渡す必要はありません。 –

+0

とにかくありがとう、しかし、私はちょうど配列を渡し、それは動作しているようだ。奇妙な!上記の私のコードでは、json_encodeを削除してcountry_optionsの配列を渡すだけで、私のために働いています。ライブラリにコード化されたものかもしれません。ところで、貴重な努力に感謝します。 –

関連する問題