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

あなたが表示された場合は、[]があります。 - これは

しかし$OUTPUT = array();内の空の配列を作成

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

答えて

1

ない$OUTPUT = array(array());

JSONArray jArray = new JSONArray(result); 

を使用してデータを解析するときはもちろん、Javaで私に問題が発生する空の配列は、私にJSONExcpetionをOccuring

+0

私はあなたの答えに恋しています:)ありがとう! –

+0

あなたは大歓迎です:) – nospor

関連する問題