2016-05-31 43 views
1

我在發帖之前做了很長時間的搜索,沒有任何解決方案適用於我。 我正在使用JSON和PHP創建一個Android應用程序;jsonencode添加一個空行,爲什麼?

PHP

/** 
* 
LOT OF USELESS THING 
* 
*/ 
//Attributing values of $OUTPUT 

$q=mysql_query($query); 

if (!$q) 
    die(mysql_error()); // You'll be notified if there's any syntax error in your query. 

$OUTPUT = array(array());   
if ($q && @mysql_num_rows($q) > 0) { 
    // looping through all results 
    // products node 

    while([email protected]_fetch_assoc($q)){ 
     if (!empty($e['title'])){ 
     $u = Array(); 
     $u['id'] = mb_convert_encoding($e['id'], 'UTF-8'); 
     $u['title'] = mb_convert_encoding($e['title'], 'UTF-8'); 
     $u['location_search_text'] = mb_convert_encoding($e['location_search_text'], 'UTF-8'); 
     $OUTPUT[] = $u;} 
     //echo "<br>************<br>";*/ 

      //$OUTPUT[] = $e; 
    } 
} 
print(json_encode($OUTPUT)); 

現在,這是JSON的輸出:

[[],{"id":"796","title":"ANSEJ ORAN \/Agence de Soutien \u00e0 l'Emploi des Jeunes d'Oran","locat ...etc 

如果你看到,有一個[];空數組,這當然使我在Java中的問題,用

JSONArray jArray = new JSONArray(result); 

分析數據時存在的我JSONExcpetion:

Error parsing data org.json.JSONException: Value [] at 0 of type org.json.JSONArray cannot be converted to JSONObject 

回答

1

$OUTPUT = array(array()); - 這裏面創建

$OUTPUT = array();空數組

+0

我愛上了你的答案:)謝謝! –

+0

不客氣:) – nospor

相關問題