0
    try {

                    String ret = jsnparse.getUrlString(params[0]);
                    ret = ret.trim();           
                    JSONObject jsonObj = new JSONObject(ret);

                    JSONArray products = jsonObj.getJSONArray(TAG_JsonArray);
                    JSONObject tmp;
                    for(int i=0; i<products.length(); i++){
                        tmp = products.getJSONObject(i);
                        FacultyMemberClass _product = new FacultyMemberClass(
                                tmp.getString(TAG_id),
                                1,
                                tmp.getString(TAG_Name)+" "+ tmp.getString(TAG_surName),
                                "(" +tmp.getString(TAG_RankPosition)+")" + tmp.getString(TAG_RankTitle), 
                                tmp.getString(TAG_Research), 
                                tmp.getString(TAG_Email),
                                tmp.getString(TAG_Office), 
                                tmp.getString(TAG_Phone),
                                tmp.getString(TAG_Photo)
                                );

                        productList.add(_product);
                    }
                } catch (SocketTimeoutException e) {
                    e.printStackTrace();
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                return productList;

            }

i am using these codes to parse my json code, it is work for http://www.gorkemkaradogan.com/Personnel.txt
but it is not runinng http://www.gorkemkaradogan.com/Personnel.aspx , when i give this url
my jsonparse class is ; `package com.example.cmpeemu;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpGet;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.http.AndroidHttpClient;


public class JSONParser {
     public static final int connectTimeout = 10*1000; // 10 seconds..


    // constructor
    public JSONParser() {

    }


    public static String getUrlString(String url)
                      throws MalformedURLException, SocketTimeoutException, IOException{
        InputStream in = null;
        BufferedReader reader = null;
        URLConnection feedUrl;
        String ret = "";
        feedUrl = new URL(url).openConnection();

        feedUrl.setConnectTimeout(connectTimeout);
        feedUrl.setReadTimeout (connectTimeout);
        in = feedUrl.getInputStream();
        reader = new BufferedReader(new InputStreamReader(in,"ISO-8859-9"));
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        ret = sb.toString();
        in.close();
        return ret;
     }



    public Bitmap downloadBitmap(String url) throws MalformedURLException, IOException {
       final AndroidHttpClient client = AndroidHttpClient.newInstance("Android");
       final HttpGet getRequest = new HttpGet(url);

       try {
          HttpResponse response = client.execute(getRequest);
          final int statusCode = response.getStatusLine().getStatusCode();
          if (statusCode != HttpStatus.SC_OK) {
             return null;
          }

          final HttpEntity entity = response.getEntity();
          if (entity != null) {
              InputStream inputStream = null;
              try {
                  inputStream = entity.getContent();
                  final Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
                  return bitmap;
              } finally {
                  if (inputStream != null) {
                     inputStream.close();
                  }
                  entity.consumeContent();
              }
          }
       } catch (MalformedURLException e) {
          getRequest.abort();
          e.printStackTrace();
       } catch (IOException e) {
          getRequest.abort();
          e.printStackTrace();
       } finally {
          if (client != null) {
              client.close();
          }
       }
       return null;
     }
}

なぜ私のaspxファイルではうまくいかないのですか。一方、私のjsonコードには、例のletudenter_enとlecturer_trの配列があり、一番上にはletudenter_enがありますが、TAG_JsonArrayがletudenter_trの場合は実行されません。コード、なぜそれが似ているのかわかりません。

4

1 に答える 1

0

aspx は json ではないため、html です。

ビューソース: http://www.gorkemkaradogan.com/Personnel.aspx

スクリーンショット

于 2013-03-22T22:26:07.457 に答える