2017-06-22 126 views
-2

需要你的這一個幫助... 我怎樣才能轉換此陣列JSON代碼...如何陣列轉換成JSON

這裏是我的代碼:

// Initiate curl 
$ch = curl_init(); 
// Disable SSL verification 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
// Will return the response, if false it print the response 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); 
// Set the url 
curl_setopt($ch, CURLOPT_URL,$url); 
// Execute 
$result=curl_exec($ch); 
// Closing 
curl_close($ch); 

// Will dump a beauty json :3 
//var_dump(json_decode($result, true)); 

//$result = file_get_contents($url); 
// Will dump a beauty json :3 
//var_dump(json_decode($result, true)); 
//write to json file 
$ssim = array($result); 
$fp = fopen('rsspb.json', 'w'); 
//have a backslashes remover 
fwrite($fp, json_encode($ssim, JSON_UNESCAPED_SLASHES)); 
fclose($fp); 

這裏的結果:

["{\"tickets\":[{\"url\":\"https://51talk.zendesk.com/api/v2/tickets/1.json\",\"id\":1,\"external_id\":null,\"via\":{\"channel\":\"sample_ticket\",\"source\":{\"from\":{},\"to\":{},\"rel\":null}},\"created_at\":\"2017-04-25T05:56:36Z\",\"updated_at\":\"2017-04-25T05:56:36Z\",\"type\":\"incident\",\"subject\":\"Sample ticket: Meet the ticket\",\"raw_subject\":\"Sample ticket: Meet the ticket\",\"description\":\"Hi Noel,\\n\\nEmails, chats, voicemails, and tweets are captured in Zendesk Support as tickets. Start typing above to respond and click Submit to send. To test how an email becomes a ticket, send a message to [email protected]\\n\\nCurious about what your customers will see when you reply? Check out this video:\\nhttps://demos.zendesk.com/hc/en- 
+2

使用json_encode($結果)?問題不清楚... –

+0

嗯...使該數組json – ivor

+0

[將PHP結果數組轉換爲JSON]可能的副本(https://stackoverflow.com/q/2122233/6521116) –

回答

0
<?php 
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5); 

echo json_encode($arr); 
?> 
+0

我怎樣才能刪除雙引號和斜線...... 「{\」tickets \「:[{\」url \「:\」https:\/\/ – ivor

+0

您還沒有刪過報價瀏覽器會自動理解。 –

+0

您的json響應複製並單擊此處以正確的格式顯示過去https://jsonformatter.curiousconcept.com/ –