2017-03-20 2 views
-2

Dies ist der Json Codecod JSON Array PHP Ich möchte ein korrektes Beispiel

{"data":{"user":{"first_name":"xx","last_name":"xx","email":"xx","countryOfResidence":"GB","country":"LK","nationality":"LK"},"billing_address":{"line1":"xx","city":"xx","postal_code":"xx","country":"LK"},"shipping_address":{"first_name":"xx","last_name":"xx","line1":"xx","city":"xx","postal_code":"xx","country":"LK"},"phone":{"type":"Mobile","number":"xx","countryCode":"94"},"marketing_optin":true,"shipping_address_validation":false,"poma_flow":false,"prox_flow":false,"testParams":{},"content_identifier":"LK:en:2.0.287:signupTerms.signupC","card":{"type":"MASTERCARD","number":"xx","security_code":"xx","expiry_month":"xx","expiry_year":"xx"},"skipInitiateAuth":true},"meta":{"token":"xx","calc":"xx","csci":"xx","locale":{"country":"LK","language":"en"},"state":"ui_checkout_guest","app_name":"xoonboardingnodeweb"}} 

Dies ist der PHP-Code, den ich den Code in korrekter Art und Weise schreiben möchten, und damit es funktioniert. Ich möchte wissen, wo meine Schuld ist. Kann jemand diese Datei von mir korrigieren? Bitte helfen Sie mit diesem Beispiel deutlich.

   $link = "https://www.paypal.com/webscr?cmd=_express-checkout&token=EC-7Y207450BE832821N#/checkout/guest"; 
       $post = ""; 
       $s = _curl($link, json_encode($post), $cookie); 



      $post = json_encode($array); 
      $array = json_decode($json_string, true); 
$link = "https://www.paypal.com/webapps/xoonboarding/api/onboard/guest"; 


            $post = [ 
     'data' => [ 
      'user' => [ 
       'first_name' => 'xx', 
       'last_name' => 'xx', 
       'email' => 'xx', 
       'countryOfResidence' => 'GB', 
       'country' => 'LK', 
       'nationality' => 'lk', 
      ], 
      'billing_address' => [ 
       'line1' => 'xx', 
       'city' => 'xx', 
       'postal_code' => 'xx', 
       'country' => 'lk', 
      ], 
      'shipping_address' => [ 
       'first_name' => 'xx', 
       'last_name' => 'xx', 
       'line1' => 'xx', 
       'city' => 'xx', 
       'postal_code' => 'xx', 
       'country' => 'lk', 
      ], 
      'phone' => [ 
       'type' => 'Mobile', 
       'number' => 'xx', 
       'countryCode' => '94', 
      ], 
      'marketing_optin' => true, 
      'shipping_address_validation' => false, 
      'poma_flow' => false, 
      'prox_flow' => false, 
      'testParams' => [], 
      'content_identifier' => "LK:en:2.0.287:signupTerms.signupC", 
      'card' => [ 
       'type' => 'xx', 
       'number' => xx, 
       'security_code' => xx, 
       'expiry_month' => xx, 
       'expiry_year' => xx, 
      ], 
      'skipInitiateAuth' => true 
     ], 
     'meta' => [ 
      'token' => xx, 
      'calc' => xx, 
      'csci' => xx, 
      'locale' => [ 
       'country' => 'LK', 
       'language' => 'en', 
      ], 
      'state' => 'ui_checkout_guest', 
      'app_name' => 'xoonboardingnodeweb', 
     ] 
    ]; 

    $s = _curl($link, json_encode($post), $cookie); 

Antwort

0

können Sie ein JSON Formatter verwenden einfach die Struktur Ihrer JSON sichtbar zu machen, und es in PHP umzusetzen. Oder Sie können einfach eine PHP-Variable erstellen, dank json_decode mit Ihnen JSON-Code im Beispiel geben.

$link = "https://www.paypal.com/webapps/xoonboarding/api/onboard/guest"; 
 

 
$data = [ 
 
    'data' => [ 
 
     'user' => [ 
 
      'first_name' => 'xx', 
 
      'last_name' => 'xx', 
 
      'email' => 'xx', 
 
      'countryOfResidence' => 'GB', 
 
      'country' => 'LK', 
 
      'nationality' => 'lk', 
 
     ], 
 
     'billing_address' => [ 
 
      'line1' => 'xx', 
 
      'city' => 'xx', 
 
      'postal_code' => 'xx', 
 
      'country' => 'lk', 
 
     ], 
 
     'shipping_address' => [ 
 
      'first_name' => 'xx', 
 
      'last_name' => 'xx', 
 
      'line1' => 'xx', 
 
      'city' => 'xx', 
 
      'postal_code' => 'xx', 
 
      'country' => 'lk', 
 
     ], 
 
     'phone' => [ 
 
      'type' => 'Mobile', 
 
      'number' => 'xx', 
 
      'countryCode' => '94', 
 
     ], 
 
     'marketing_optin' => true, 
 
     'shipping_address_validation' => false, 
 
     'poma_flow' => false, 
 
     'prox_flow' => false, 
 
     'testParams' => [], 
 
     'content_identifier' => "LK:en:2.0.287:signupTerms.signupC", 
 
     'card' => [ 
 
      'type' => 'xx', 
 
      'number' => 'xx', 
 
      'security_code' => 'xx', 
 
      'expiry_month' => 'xx', 
 
      'expiry_year' => 'xx', 
 
     ], 
 
     'skipInitiateAuth' => true 
 
    ], 
 
    'meta' => [ 
 
     'token' => 'xx', 
 
     'calc' => 'xx', 
 
     'csci' => 'xx', 
 
     'locale' => [ 
 
      'country' => 'LK', 
 
      'language' => 'en', 
 
     ], 
 
     'state' => 'ui_checkout_guest', 
 
     'app_name' => 'xoonboardingnodeweb', 
 
    ] 
 
]; 
 

 
$json = json_encode($data, true); 
 
                                                                    
 
$ch = curl_init($link);                  
 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                  
 
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);                 
 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                  
 
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json', 'Content-Length: ' . strlen($json)]);                  
 
                                                      
 
$result = curl_exec($ch);

+0

Können Sie diesen Code korrekt? –

+0

Vergleicht man die beiden Strukturen, scheint der PHP-Code korrekt zu sein. Was die HTTP-Anfrage Antwort? – Schnapse

+0

Ich brauche JSON zu Array PHP IN Beispiel –