Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android解析的Aspx文件和txt文件不同 试试看{ String ret=jsnpasse.getUrlString(参数[0]); ret=ret.trim(); JSONObject jsonObj=新的JSONObject(ret); JSONArray products=jsonObj.getJSONArray(TAG_JSONArray); JSONObject tmp; 对于(int i=0;i_Android_Json_Parsing - Fatal编程技术网

android解析的Aspx文件和txt文件不同 试试看{ String ret=jsnpasse.getUrlString(参数[0]); ret=ret.trim(); JSONObject jsonObj=新的JSONObject(ret); JSONArray products=jsonObj.getJSONArray(TAG_JSONArray); JSONObject tmp; 对于(int i=0;i

android解析的Aspx文件和txt文件不同 试试看{ String ret=jsnpasse.getUrlString(参数[0]); ret=ret.trim(); JSONObject jsonObj=新的JSONObject(ret); JSONArray products=jsonObj.getJSONArray(TAG_JSONArray); JSONObject tmp; 对于(int i=0;i,android,json,parsing,Android,Json,Parsing,,因为您的aspx不是json,所以它是html: 查看来源: 我放了标签,里面有我的json代码。我的json创建代码是这样的对不起,我不熟悉aspx:)你只需要返回简单的json,而不是标签中包含json的html。我找到了解决方案,谢谢大家的响应。Write(str);这是要写的代码 try { String ret = jsnparse.getUrlString(params[0]); ret =

,因为您的aspx不是json,所以它是html:

查看来源:


我放了标签,里面有我的json代码。我的json创建代码是这样的对不起,我不熟悉aspx:)你只需要返回简单的json,而不是标签中包含json的html。我找到了解决方案,谢谢大家的响应。Write(str);这是要写的代码
    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;
     }
}