2017-06-22 2 views
-2

besoin de votre aide sur celui-ci ... Comment convertir ces tableaux au code JSON ...Comment convertir tableau en JSON

voici mon code:

// 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); 

Voici le résultat:

["{\"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

en utilisant json_encode ($ result)? La question n'est pas claire ... –

+0

hmm ... ineed pour rendre les tableaux à json – ivor

+0

Copie possible de [Convertir le tableau de résultats PHP en JSON] (https://stackoverflow.com/q/2122233/6521116) –

Répondre

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

echo json_encode($arr); 
?> 
+0

comment puis-je supprimer le guillemet et les barres obliques? "{\" tickets \ ": [{\" url \ ": \" https: \/\/ – ivor

+0

Vous n'avez pas besoin de supprimer le devis devis automatiquement comprendre. –

+0

Votre copie de réponse json et cliquez ici au bon format dans le passé https://jsonformatter.curiousconcept.com/ –