mega94
mega94

Reputation: 113

How to get the string to Json format

How to convert a JSON string into an array for this query?

Request code:

$cookies=tmpfile();
$ch = curl_init("https://s.taobao.com/search?ajax=true&callback=&app=imgsearch&tfsid=TB1jNPyLFXXXXXxXFXXXXXXXXXX");
curl_setopt($ch, CURLOPT_USERAGENT, 'IE20');
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);//используем куки
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
$page=curl_exec($ch);
curl_close($ch);
substr($page, 0, -1);
$json = json_decode($page,true);
print_r($page);

Upvotes: 0

Views: 84

Answers (2)

Sharma Vikram
Sharma Vikram

Reputation: 2470

you should try this it will work

<?php
ini_set('max_execution_time', -1);
header('Content-Type: application/json');
$data=file_get_contents("http://tajmarket.ru/tetes/files/");
echo json_encode($data);
?>

Upvotes: 2

Riyaz
Riyaz

Reputation: 139

Please check the data. A numeric 1 is present at the end of the file. Please remove it.

Upvotes: 0

Related Questions