2016-05-31 6 views
1

Я сделал длинный поиск перед публикацией, ни один из решений не работает для меня. Я создаю приложение для Android, используя JSON и PHP;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

Смежные вопросы