私は実際にApiの世界では新しく、私はCurl Requestを使用してデータをフェッチして返信するApiで作業しています。フェッチでは、以下の情報が渡されます。Jsonでエンコードされた配列PHPを使用して分割
{"posts":{"userinfo":{"fullname":"Precious Tom","user_name":"Kendrick","email":"[email protected]","gender":"Male","country":"Nigeria","city":"Port Harcourt","state":"Rivers","year":"1997","month":"9","day":"6"}}}
コンテンツタイプ:text/html;文字セット= UTF-8
HTTPコード:アレイを分割200
は私の問題のように見える、ごめん、この質問のHSは以前に頼まれて、しかし、私はあなたの助けを必要としてください場合。おかげさまで
は、詳細については、ここでは私のカールリクエスト
<?php
session_start();
# data to be sent
$data = array(
'public_key' => 'pk_test_3gc9ffb0hccggf5f3b4e258da848343dff4ae900',
'app_name' => 'Circlepanda',
'app_id' => '2147483647'
);
$curl = curl_init();
# you can also set the url you wanna communicate with by setting
# $curl = curl_init('http://localhost/circlepanda');
# We post Data
curl_setopt($curl, CURLOPT_POST, 1);
# Set the url path we want to call
curl_setopt($curl, CURLOPT_URL, 'http://localhost:8888/circlepanda/api/userinfo');
# Make it so the data coming back is put into a string
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
# You can also bunch the above commands into an array if you choose using: curl_setopt_array
# Send the request
$result = curl_exec($curl);
# Get some cURL session information back
$info = curl_getinfo($curl);
echo '<br> content type: ' . $info['content_type'] . '<br>';echo 'http code: ' . $info['http_code'] . '<br>';
# Free up the resources $curl is using
curl_close($curl);
?>
私は変数ではない直接の配列を渡すことになりますです。 json
を変換する -
1: しようとした直接の配列は、あなたのコードは、あなたが2つのオプションをした、それは動作を停止...
詳細については、こちらをご覧くださいので、問題 – JYoThI
は、あなたがこれまでに – Kuru
ますprint_r(json_decode( '{ "投稿を" 試されている任意のコードを表示するものである:
json
を使用してarray
に変換します{"userinfo":{"fullname": "Precious Tom"、 "user_name": "Kendrick"、 "email": "[email protected]"、 "gender": "男性"、 "国" 「都市」、「ポートハーコート」、「州」、「川」、「年」、「1997」、「月」:「9」、「日」:「6」}}} '、真)); – JYoThI