Aspx文件和txt文件不同,用于android解析

时间:2013-03-22 22:23:58

标签: android json parsing

    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代码中,有一些数组用于exapmle lecturer_en和lecturer_tr, 在顶部有讲员_en 但是当TAG_JsonArray是讲话者时,它不会运行,它必须位于代码的顶部,我不知道为什么会这样。

1 个答案:

答案 0 :(得分:0)

因为你的aspx不是json,它是html:

视图源:http://www.gorkemkaradogan.com/Personnel.aspx

screenshot