Help convert string to json array such request

such code:

<? header("Content-Type: text/html; charset=utf-8"); //if($_SERVER["REQUEST_METHOD"] == "POST"){ $keyword = $_POST['id']; $data = array( 'iframe_delete'=>'true', 'varname'=> 'intelSearchData', '__number'=> '2', 'keyword'=> 'камера'//$keyword, ); $ch = curl_init('http://connectkeyword.aliexpress.com/lenoIframeJson.htm?'.http_build_query($data)); curl_setopt($ch, CURLOPT_USERAGENT, 'IE20'); curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/cookies.txt'); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); $page=curl_exec($ch); curl_close($ch); $json = substr($page, 45, -9); //$json = json_decode($json); print_r($json); //} ?> 

    1 answer 1

    Well, you can try json_decode :

     $obj = json_decode($jsondata, true); 

    Well, $obj is a multidimensional array.

    And if you want to use js to do this, then use JSON.parse(string) after taking your string in var string.

    • so already did not help shows emptiness. - mega94
    • So you, for that link, an array of clumsy. These cells should be in double quotes, as names and values, and not in single, like you. Otherwise decode-p will not be able to bypass the string normally. Regarding numbers, you have several count-s using this type of "8,059". If this number is an integer, get rid of the division into thousands, the number must not contain commas, or it must be in quotes. - Wayer
    • and if JSON.parse(string) through JSON.parse(string) is easier to think so? - mega94
    • This does not change the essence of the matter. You have an array that goes to the invalid parser - Wayer
    • one
      $jsondata = str_replace("'", '"', $jsondata); do the same with all your id's in the array: $jsondata = str_replace('id','"id"', $jsondata); - Wayer