2012-01-08 9 views
0

PHPファイルがあり、アンドロイドデバイスに配列を送信しています。私のデバイスは、データを受け取った後、それを文字列に変換し、その後私はPHPで作られたassoc配列のインデックスを取得しようとしています。ここでは前からPHPコードのサンプルです:データを文字列に変換しようとしているときのJSONException

protected void onPostExecute(String result) { 

     dialog.dismiss(); 

     try{ 
      jArray = new JSONArray(result); 
      JSONObject json_data=null; 

      for(int i = 0; i < jArray.length(); i++){ 

       json_data    = jArray.getJSONObject(i);  

       String getMessage = json_data.getString("message"); 
       showToast(getMessage); 
      } 
     } 
     catch(JSONException je){ 
      Log.e("log_tag", "Error (JSONException): "+je.toString()); 
      showToast(result); 
     } 
     catch (ParseException pe) { 
      pe.printStackTrace(); 
     } 
    } 

エラーログ:

if(mysql_num_rows($query)){ 
    $output = array('message' => 'Group added to your database', 'succes' => 'true'); 

}else{ 
    $output = array('message' => 'Wrong username/password combination', 'succes' => 'false'); 
} 

print(json_encode($output)); 

、ここでは私のAndroidのプロジェクト内のコードがどのように見えるかです

01-08 16:35:55.896: E/log_tag(647): Error (JSONException): org.json.JSONException: Value {"message":"Group added to your database","success":"true"} of type org.json.JSONObject cannot be converted to JSONArray 
01-08 16:35:56.186: W/TextLayoutCache(647): computeValuesWithHarfbuzz -- need to force to single run 
+0

Jsonの例外にはどのような詳細がありますか?また、succesは「成功」と綴られています。 –

+0

エラー(JSONException):org.json.JSONObject型の値{"メッセージ": "グループがデータベースに追加されました"、 "成功": "true"}はJSONArrayに変換できません – Xarialon

答えて

1

あなたは、 JSONObjectを表す文字列からJSONArrayを作成しようとすると、次のようになります。

+0

あまりにも、しかし、問題を解決する方法をかなり知りませんでした。 Thanx :) – Xarialon

関連する問題