2016-05-31 45 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

相关问题