2016-04-16 19 views
-1

私はjsonの文字列を持っていますが、json_decode()を取得すると空白が表示されます。jsonの文字列が空白で表示されていますなぜ


$str = '[{"actcode":"Auck4","actname":"Sky Tower","date":"","time":"","timeduration":"","adult":"0","adultprice":"28","child":"0","childprice":"0","description":"Discover the best of Auckland in half a day. Soak up spectacular sights on this scenic tour, from heritage-listed buildings on Queen Street to the stunning Viaduct Harbour and panoramic vistas from the Sky Tower observation deck. 

Start your tour with a hotel pick-up and travel through Auckland?s dynamic Central Business District. Travel across the iconic Auckland Harbour Bridge and admire stunning city views. Then, return to the city centre and visit the vibrant precinct of Wynyard Quarter. Here, wander among the sculptures and enjoy the happenings on the water of Viaduct Harbour. 

Continue to Queen Street, also known as the ?Golden Mile? of Aucklands business and shopping district. Marvel at historic buildings like the Ferry Terminal building before visiting the Auckland Museum. Here, explore fascinating exhibits paying tribute to New Zealands natural, Maori and European histories. Afterwards, travel along Aucklands most expensive residential streets with fantastic views of the Waitemata Harbour and its islands. 

Your tour ends at Sky Tower, the tallest free-standing structure in the Southern Hemisphere. Take in breathtaking 360-degree views of the city and its surroundings. In the afternoon, continue your own exploration of Auckland."}]'; 

私も

$str1 = trim($str); 
$array = json_decode($str1,true); 
echo print_r($array); 

が、空白


+1

JSONが無効です。エラーをデバッグするために 'json_last_error_msg()'を使用してください – Machavity

+4

[PHP json \ _decode()の不正なjsonデータを検出しますか?](http://stackoverflow.com/questions/2348152/detect-bad-json-data-in) -php-json-decode) – Machavity

+0

余分なスペースと改行スペースを削除すると、デコードが行われます –

答えて

-2
を示す文字列SI以下のコード

$array = json_decode($str,true); 
echo print_r($array); 

にこの1を試してみました

これを試してください。

$string = mysql_real_escape_string($str); 
$findsym = array('\r', '\n'); 
$removesym = array("", ""); 
$strdone = stripslashes(str_replace($findsym,$removesym,strip_tags($string))); 
$jsonarray = json_decode($strdone,true); 
echo "<pre>"; echo print_r($jsonarray); 
関連する問題