我已經創造了你,我講一個例子,響應使用捲曲功能: -
1.My兩個文件(php
代碼文件和json
字符串文件),在相同的工作directory.Check: - http://prntscr.com/apkbp9
2. json
字符串文件內容應該是: -
[
{
"email" : "",
"Name" : "Ddd",
"contact2" : "",
"ontact1" : ""
},
{
"email" : "",
"Name" : "Ddd",
"contact2" : "",
"contact1" : ""
},
{
"email" : "",
"Name" : "Dddddr",
"contact2" : "",
"contact1" : ""
}
]
檢查這裏: - http://prntscr.com/apkbx0
3. php
代碼文件的內容: -
<?php
$inputJSON = file_get_contents('input.txt');
echo $inputJSON;
$data = json_decode($inputJSON, TRUE);
echo "<pre/>";print_r($data);
?>
入住這裏: - http://prntscr.com/apkc6x
輸出上我的瀏覽器: - http://prntscr.com/apkcoi
您可以使用CURL
像如下: -
<?php
function url_get_contents ($Url) {
if (!function_exists('curl_init')){
die('CURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
$inputJSON = url_get_contents('php://input');
echo $inputJSON;
$data = json_decode($inputJSON, TRUE);
echo "<pre/>";print_r($data);
?>
更多參考有關CURL
: - http://php.net/manual/en/book.curl.php
注: - 如果兩個都不行,那麼首先您需要保存在擴展.txt
文件您json
數據,然後你可以使用上面給出這兩個代碼,只需通過放置該文本文件的完整路徑。
'$ inputJSON'是否有值? – aldrin27
echo $ inputJSON;什麼也沒給 var_dump($ inputJSON);返回字符串(0)「」 – Lydia
php://輸入這是我以前工作。 – Lydia