-1

我正在使用 url 来获取文件进行解析。我想读取 url 属性并将它们放在 textview 中。下面是我的网址

https://graph.facebook.com/fql?q=SELECT+app_id,namespace,category+FROM+application+WHERE+namespace=%22graffitiwall%22

这个怎么做

4

1 回答 1

1

将您当前的 json 字符串解析为:

public  class JSONTask extends 
                  AsyncTask<String, Void, String> {
    @Override
    protected String doInBackground(String... arg) {
        String linha = "";
        String retorno = "";
        // Cria o cliente de conexão
        HttpClient client = new DefaultHttpClient();
        HttpGet get = new HttpGet("https://graph.facebook.com
                   /fql?q=SELECT+app_id,namespace,category+
                 FROM+application+WHERE+namespace=graffitiwall%22");

        try {
            HttpResponse response = client.execute(get);

            StatusLine statusLine = response.getStatusLine();
            int statusCode = statusLine.getStatusCode();

            if (statusCode == 200) { // Ok
              BufferedReader rd = new BufferedReader(new 
              InputStreamReader(response.getEntity().getContent()));

              while ((linha = rd.readLine()) != null) {
                    retorno += linha;
              }
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return retorno; 
    }

    @Override
    protected void onPostExecute(String result) {
        // Create here your JSONObject...

    // getting JSON string from URL
    JSONObject json = new JSONObject(result);

     // Getting Array of data
    JSONArray userlist = json.getJSONArray("data");

    for(int i = 0; i < userlist.length(); i++){
         JSONObject c = userlist.getJSONObject(i);

         // Storing each json item in variable
          String str_app_id = c.getString("app_id");              
          String str_namespace = c.getString("namespace");
          String str_category = c.getString("category");
     }

    }
于 2012-12-12T10:38:34.180 回答