Not getting complete data from Json

u_pendra

Here I am trying to get Json data from URL. But oit is displaying only partial data. Below are the details how I am reading the data

BufferedInputStream is;

HttpGet httpGet = new HttpGet(url);
httpGet.addHeader("Accept", "application/json");
HttpResponse httpResponse = getHttpClient().execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = new BufferedInputStream(httpEntity.getContent()) ;

public void getJsonwithByteArray(BufferedInputStream istream) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    int ctr;
    try {
        ctr = istream.read();
        while (ctr != -1) {
            byteArrayOutputStream.write(ctr);
            ctr = istream.read();
        }
        istream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    Log.v("Text Data", byteArrayOutputStream.toString());
    try {

        // Parse the data into jsonobject to get original data in form of
        // json.
        JSONObject jObject = new JSONObject(
                byteArrayOutputStream.toString());
        jObj = jObject;

        Log.v("JsonParser", "JsonByteArry data: " + jObj.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Biraj Zalavadia

Try this method to Read Response

public String getResponseBody(final HttpEntity entity) throws IOException, ParseException {


        if (entity == null) {
            throw new IllegalArgumentException("HTTP entity may not be null");
        }

        InputStream instream = entity.getContent();

        if (instream == null) {
            return "";
        }

        if (entity.getContentLength() > Integer.MAX_VALUE) {
            throw new IllegalArgumentException(

            "HTTP entity too large to be buffered in memory");
        }


        StringBuilder buffer = new StringBuilder();

        BufferedReader reader = new BufferedReader(new InputStreamReader(instream, HTTP.UTF_8));

        String line = null;
        try {
            while ((line = reader.readLine()) != null) {
                buffer.append(line);
            }

        } finally {
            instream.close();
            reader.close();
        }

        return buffer.toString();

    }

How to use?

HttpGet httpGet = new HttpGet(url);
httpGet.addHeader("Accept", "application/json");
HttpResponse httpResponse = getHttpClient().execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
String response = getResponseBody(httpEntity);
try {

        // Parse the data into jsonobject to get original data in form of
        // json.
        JSONObject jObject = new JSONObject(
                response);
        jObj = jObject;

        Log.v("JsonParser", "JsonByteArry data: " + jObj.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Getting data from database and use it to complete a form - Wordpress

분류에서Dev

getting json data from web and list them in android

분류에서Dev

jquery $.each nested in another $each. getting data from a JSON

분류에서Dev

Cannot getting data from external nested json file form jquery

분류에서Dev

Getting JSON from Form

분류에서Dev

JTable not getting data from Vector

분류에서Dev

R: Getting data from list

분류에서Dev

JTable not getting data from Vector

분류에서Dev

Vue.js: v-repeat not getting data from JSON array

분류에서Dev

Getting JSON and evaluating data with just javascript

분류에서Dev

JSON Data from api

분류에서Dev

Getting NegativeArraySizeException while JSON parsing from openweathermap

분류에서Dev

getting 2 JSON arrays from php to js

분류에서Dev

KnockoutJS - Getting ViewModel data from a Nested Object

분류에서Dev

getting data from 2 tables and writing a query

분류에서Dev

Getting data from url using PHP

분류에서Dev

$_POST not getting data from HTML Form

분류에서Dev

Extending data from json in customDimensions

분류에서Dev

retrieve data json from inlocalstorage

분류에서Dev

Print data from json file

분류에서Dev

Saving variable data from jQuery to PHP and getting it after page reload

분류에서Dev

Getting data of Child Element from its Parent counterpart

분류에서Dev

Hibernate returns null for an integer after getting the data from db in Java

분류에서Dev

Getting data from symfony controller in Typeaahead.js

분류에서Dev

Getting data from a shared iCloud ical using java script

분류에서Dev

c# getting data from xml deserialized object

분류에서Dev

Getting data (floats) from a url in Obj-C (Xcode)

분류에서Dev

Showing path on google map from json data

분류에서Dev

How to return rows of data from a table with json?

Related 관련 기사

뜨겁다태그

보관