开发者

How to solve json parsing error?

I am working on android application.I am sending Http url to the client and get back json from them. but the received json is very large so that i can't store the json values to the String. so I am getting Enlarge buffer error

So is there any solution available to parse json value to String.I have attached My code below...

package ez.com;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.ObjectInputStream.GetField;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import org.json.JSONArray;
import org.json.JSONObject;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.text.Html;
import android.widget.Toast;

public class apiconnection {
    /** Called when the activity is first created. */

    public static URL                url; 
    public static URLConnection      urlConn; 
    public static DataInputStream    dis;
    public String str;
    public static int val;

    public static void urlconn(String url_val,Context con)
    {
        String s;
        //StringBuilder sb = new StringBuilder();
        StringBuffer sb=new StringBuffer();
        String jsonval=null;

        try
        {

            String urlval="http://iphone.openmetrics.com/apps/mattson/api.html"+url_val;

            System.out.println("url value for connection: " +urlval);        
            url = new URL(urlval);          
            urlConn = url.openConnection(); 
            urlConn.setDoInput(true); 
            urlConn.setUseCaches(false);
            dis = new DataInputStream(urlConn.getInputStream()); 

            if(dis.available()==0)
            {
                Toast.makeText(con, "No Data found Please search another option", Toast.LENGTH_LONG开发者_Go百科).show();
                AlertDialog.Builder ab=new AlertDialog.Builder(con);
                ab.setMessage(Html.fromHtml("<b><font color=#ff0000> Network Error Please try Again" +"</font></b>"));
                ab.setPositiveButton("ok", null);
                ab.show();

            }

            while ((s = dis.readLine()) != null)
            {             

                sb.append(s);

            }           
            "**jsonval=sb.toString();**" -------------------->This line is error
            System.out.println("Json Parsed " +jsonval);
            jsonreader.json(sb.toString()); 


        }  
        catch (MalformedURLException e) 
        {
              throw new IllegalStateException("Malformed URL for : "+ e);
         }
         catch (IOException e) 
         {
              throw new IllegalStateException("IO Exception for  : " + e);
         }

    }

}


Would it work to split up the JSON data into parseable parts that are small enough to fit into the buffer?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜