Android Open Source - SSPIA J S O N Parser






From Project

Back to project page SSPIA.

License

The source code is released under:

MIT License

If you think the Android project SSPIA listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.fiec.sspia.util;
//from   w  ww .ja v a 2  s . c  o m

import java.io.*;
import java.util.List;
 

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.*;

import com.fiec.sspia.buff.Tag;

import android.util.Log;
 
public class JSONParser {
 
    static InputStream is = null;
    static JSONObject json = null;
    static String aux2 = null;
 
    public JSONParser() {
 
    }
    
    public String makeHttpRequestPOST(String url, String method, List<NameValuePair> params1){
      try{
        if(method == "POST"){
              DefaultHttpClient httpClient = new DefaultHttpClient();
              HttpPost httpPost = new HttpPost(url);
              httpPost.setEntity(new UrlEncodedFormEntity(params1));
  
              HttpResponse httpResponse = httpClient.execute(httpPost);
              HttpEntity httpEntity = httpResponse.getEntity();
              is = httpEntity.getContent();
              convertResult();                
          }
      }catch (UnsupportedEncodingException e) {
        Log.w(Tag._TAG, e.toString());
      } catch (ClientProtocolException e) {
        Log.w(Tag._TAG, e.toString());
      } catch (IOException e) {
        Log.w(Tag._TAG, e.toString());
      }
      return aux2;
    }
    
    public JSONObject makeHttpRequest(String url, String method){
      json = null;
        try {
 
            if(method == "GET"){
                DefaultHttpClient httpClient = new DefaultHttpClient();
                //String paramString = URLEncodedUtils.format(params1, "utf-8");
                //url += "?" + paramString;
                HttpGet httpGet = new HttpGet(url);
 
                HttpResponse httpResponse = httpClient.execute(httpGet);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();   
                convertResult();  
            }          
            
 
        } catch (UnsupportedEncodingException e) {
           Log.w(Tag._TAG, e.toString());
        } catch (ClientProtocolException e) {
          Log.w(Tag._TAG, e.toString());
        } catch (IOException e) {
          Log.w(Tag._TAG,e.toString());
        }
    return sendResult();
    }
 
    public JSONObject makeHttpRequest(String url, String method,
            List<NameValuePair> params1) {
      json = null;
        try {
 
            if(method == "GET"){
                DefaultHttpClient httpClient = new DefaultHttpClient();
                String paramString = URLEncodedUtils.format(params1, "utf-8");
                url += "?" + paramString;
                HttpGet httpGet = new HttpGet(url);
 
                HttpResponse httpResponse = httpClient.execute(httpGet);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();   
                convertResult();  
            }          
            
 
        } catch (UnsupportedEncodingException e) {
           Log.w(Tag._TAG, e.toString());
        } catch (ClientProtocolException e) {
          Log.w(Tag._TAG, e.toString());
        } catch (IOException e) {
          Log.w(Tag._TAG,e.toString());
        }
    return sendResult();
    }
        

    private void convertResult(){
      try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    is, "iso-8859-1"), 8);
            String line;
            StringBuilder sb = new StringBuilder();
            String aux = ""; 
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
            aux = sb.toString();
            aux2 = aux;
            is.close();
            reader.close();
           
        } catch (Exception e) {
            Log.e(Tag._TAG, "Error converting result " + e.toString());
        }
    }
    
    private JSONObject sendResult(){
      try {
          json = new JSONObject(aux2);
        } catch (Exception e) {
            Log.e(Tag._TAG, "Error parsing data " + e.toString());
        }
 
        return json;
    }
}




Java Source Code List

com.fiec.sspia.buff.DefaultNoti.java
com.fiec.sspia.buff.PlanetClass.java
com.fiec.sspia.buff.PlanetSource.java
com.fiec.sspia.buff.Tag.java
com.fiec.sspia.db.Celestial.java
com.fiec.sspia.db.DBHelper.java
com.fiec.sspia.db.DbAuxClass.java
com.fiec.sspia.db.Planets.java
com.fiec.sspia.db.Satellites.java
com.fiec.sspia.db.SolarDb.java
com.fiec.sspia.main.InformationTab.java
com.fiec.sspia.main.SatellitesClass.java
com.fiec.sspia.main.SolarActivity.java
com.fiec.sspia.main.TabsPlanets.java
com.fiec.sspia.mclass.MainClass.java
com.fiec.sspia.mclass.MainFragment.java
com.fiec.sspia.mclass.SSNotific.java
com.fiec.sspia.mclass.SetttingsClass.java
com.fiec.sspia.mclass.SplashClass.java
com.fiec.sspia.system.BroadcastRec.java
com.fiec.sspia.system.SspiaService.java
com.fiec.sspia.system.StartingNotis.java
com.fiec.sspia.util.AbstrCd.java
com.fiec.sspia.util.CdClass.java
com.fiec.sspia.util.CustomInfoAdapter.java
com.fiec.sspia.util.CustomMenuAdapter.java
com.fiec.sspia.util.FillMenuAdapter.java
com.fiec.sspia.util.JSONParser.java
com.fiec.sspia.util.MainGridAdapterClass.java
com.fiec.sspia.util.MenuSettings.java
com.fiec.sspia.util.SSInterfaceNoti.java
com.fiec.sspia.util.SatelliteGridAdapterClass.java
com.fiec.sspia.util.TempClass.java
com.fiec.sspia.util.TransitionClass.java