2017-06-22 93 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/ –