捲曲JSON陣列響應我有像這樣轉相聯繫的數組
$ch = curl_init();
$data = 'filter=year(StartTime)' . urlencode(' eq 2013 and ') .'month(StartTime)'. urlencode(' eq 06') ;
curl_setopt($ch, CURLOPT_URL, "http://url.com/id()/events?$".$data);
$headers = array(
'Accept: application/json',
'Content-type: application/json',
'X-ApiKey : XXXXXXXXXX'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, false);
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response, true);
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<body>
<br><br>
<?php
echo "the name". $result['Name'];
?>
</body>
</html>
這是它打印的捲曲請求。
HTTP/1.1 200 OK Cache-Control: no-cache Pragma: no-cache Content-Length: 218 Content-Type: application/json; charset=utf-8 Expires: -1 Server: Microsoft-IIS/7.5 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET- WEBSRV X-Powered-By: ARR/2.5 X-Powered-By: ASP.NET - ARR02 Date: Mon, 01 Jul 2013 02:52:31 GMT [{"Id":1079,"Name":"Test ","Status":1,"MemberId":1308,"Description":"This is a Test Event","SponsoredBy":null,"StartTime":"2013-06-30T12:00:00","EndTime":"2013-06-30T23:59:00","SearchDescription":null,"Types":[1,4,6]}]
the name
我怎樣才能把它放到關聯數組中?
我已經試過這
json_decode($response,true));
這
ksort($response);
這
var_dump($response);
和似乎沒有任何工作..
我希望能夠像這樣輸出
echo $reponse['Name'];
任何幫助?由於
你提到'var_dump($ response);'「不起作用」 - 它給你什麼?你是否努力從CURL調用中獲取JSON字符串,或者努力將其解碼爲數組? – IMSoP
如果我這樣做'$ response = var_dump($ response); echo $ response ['Name'];'在輸出這個'布爾(真)'似乎從CURL得到JSON字符串罰款..只是不能得到它關聯數組 – vinylDeveloper
@IMSoP我認爲它有一些東西用我的返回字符串。一些值是整數和數組,它們周圍沒有引號。你知道我該如何處理這個?這可能是問題嗎? – vinylDeveloper