2010-11-28 6 views
-1

私のリストプログラムに問題があります。どのようにアンドロイドでウェブ上でリストオブジェクトデータを表示するのですか?これは私のコードです アンドロイドのリストオブジェクトページを表示するには?

 
public void loadData() { 
     String data = txtSeach.getText().toString(); 
     textView = (TextView) findViewById(R.id.mytextView); 
     String result = ""; 
     // the year data to send 
     ArrayList nameValuePairs = new ArrayList(); 
     nameValuePairs.add(new BasicNameValuePair("search", data)); 
     InputStream is = null; 
     // http post 
     try { 
      URL url = new URL(" http://www.grouprecipes.com/search "); 
      URLConnection connection = url.openConnection(); 
      connection.connect(); 
      HttpClient httpclient = new DefaultHttpClient(); 
      HttpPost httppost = new HttpPost(" http://www.grouprecipes.com/ " 
        + data + "/"); 
      httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 
      HttpResponse response = httpclient.execute(httppost); 
      HttpEntity entity = response.getEntity(); 
      is = entity.getContent(); 
     } catch (Exception e) { 
      Log.e("log_tag", "Error in http connection " + e.toString()); 
     } 
     // convert response to string 
     try { 
      BufferedReader reader = new BufferedReader(new InputStreamReader(
        is, "iso-8859-1"), 8); 
      StringBuilder sb = new StringBuilder(); 
      String line = null; 
      while ((line = reader.readLine()) != null) { 
       sb.append(line + "\n"); 
      } 
      is.close();

result = sb.toString(); textView.append(result); } catch (Exception e) { Log.e("log_tag", "Error converting result " + e.toString()); } // parse json data try { JSONArray jArray = new JSONArray(result); for (int i = 0; i < jArray.length(); i++) { // JSONObject json_data = jArray.getJSONObject(i); JSONObject jsonObject = new JSONObject(result); // textView.setTag(json_data); // textView.getContext(); /* * Log.i("log_tag","id: "+json_data.getInt("id")+ * ", name: "+json_data.getString("name")+ * ", sex: "+json_data.getInt("sex")+ * ", birthyear: "+json_data.getInt("birthyear") * *); */ } } catch (JSONException e) { Log.e("log_tag", "Error parsing data " + e.toString()); } }`
+2

どのようなエラーが表示されますか? –

+0

4年前に尋ねられました! – Nayan

答えて

0

http://www.grouprecipes.com/へのあなたのHTTP POST要求はJSONではなくHTMLを返しています。

+0

はい...私のアプリでJSONを完成させ、ビューを完成させるには、リストを使用してください。助けてください...ありがとう – laabroo

+0

HTMLはJSONではなく、簡単にJSONできません。サイト運営者にこのデータをJSONとして提供するよう依頼してください。 –

関連する問題