Why is JSON document not fully consumed?

后端 未结 2 2013
挽巷
挽巷 2021-01-20 08:15

I\'m trying to retrieve JSON data from an external source for practice. I have gotten all the code in place but for some reason I get an error saying that the document is no

2条回答
  •  不要未来只要你来
    2021-01-20 09:08

    The value is being pass, but however null is also getting passed with it so use an if statement rather than using while like this..

    if (myJSON != null) {
                    myJSON = bufferedReaderObject.readLine();
                    completeJSONdata += myJSON;
                }
    

    then convert in Gson like this..

        Gson gson = new Gson();
        deserializedContainerObject = gson.fromJson(completeJSONdata, DeserializedContainer.class);
    

    write the getters and setters in DeserializedVariables class

    public String getMovieName() {
             return movieName;
         }
    
         public void setMovieName(String movieName) {
             this.movieName = movieName;
         }
    
         public Integer getMovieYear() {
             return movieYear;
         }
    
         public void setMovieYear(Integer movieYear) {
             this.movieYear = movieYear;
         }
    
         public Double getMovieRating() {
             return movieRating;
         }
    
         public void setMovieRating(Double movieRating) {
             this.movieRating = movieRating;
         }
    

    And now you can retrieve it in your onPostExecute() like this..

    @Override
        protected void onPostExecute( DeserializedContainer result) {
    
            mListener.onSuccess( result );
    
            for (int i = 0; i 

提交回复
热议问题