2016-01-25 2 views
2

Хотя есть много сообщений об этой теме для android Мне не удалось найти объяснения ситуации, когда это происходит в середине моего сеанса JSON.JSONException: Объект был собран Невозможно оценить JSONObject.toString()

Результаты для моего GET показаны ниже и переданы в метод parsePopularMovieJson (String json) ниже.

{ 
    page:1, 
    results:[ 
     { 
     poster_path:"/fYzpM9GmpBlIC893fNjoWCwE24H.jpg", 
     adult:false, 
     overview:"Thirtyyears after defeating the Galactic Empire, Han Solo and his alliesface a new threat from the evil Kylo Ren and his army ofStormtroopers.", 
     release_date:"2015-12-18", 
     genre_ids:[ 
      28, 
      12, 
      878, 
      14 
     ], 
     id:140607, 
     original_title:"Star Wars: The Force Awakens", 
     original_language:"en", 
     title:"Star Wars: The Force Awakens", 
     backdrop_path:"/njv65RTipNSTozFLuF85jL0bcQe.jpg", 
     popularity:57.865219, 
     vote_count:2529, 
     video:false, 
     vote_average:7.84 
     }, 
     { 
     poster_path:"/mSvpKOWbyFtLro9BjfEGqUw5dXE.jpg", 
     adult:false, 
     overview:"A cryptic message from Bond’s past sends him on a trail touncover a sinister organization. While M battles political forces tokeep the secret service alive, Bond peels back the layers of deceit toreveal the terrible truth behind SPECTRE.", 
     release_date:"2015-10-26", 
     genre_ids:[ 
      28, 
      12, 
      80 
     ], 
     id:206647, 
     original_title:"Spectre", 
     original_language:"en", 
     title:"Spectre", 
     backdrop_path:"/wVTYlkKPKrljJfugXN7UlLNjtuJ.jpg", 
     popularity:51.83321, 
     vote_count:1697, 
     video:false, 
     vote_average:6.32 
     }, 
     { 
     poster_path:"/oXUWEc5i3wYyFnL1Ycu8ppxxPvs.jpg", 
     adult:false, 
     overview:"In the1820s, a frontiersman, Hugh Glass, sets out on a path of vengeanceagainst those who left him for dead after a bear mauling.", 
     release_date:"2015-12-25", 
     genre_ids:[ 
      37, 
      18, 
      12, 
      53 
     ], 
     id:281957, 
     original_title:"The Revenant", 
     original_language:"en", 
     title:"TheRevenant", 
     backdrop_path:"/uS1SkjVviraGfFNgkDwe7ohTm8B.jpg", 
     popularity:46.269385, 
     vote_count:750, 
     video:false, 
     vote_average:7.32 
     }, 
     { 
     poster_path:"/5aGhaIHYuQbqlHWvWYqMCnj40y2.jpg", 
     adult:false, 
     overview:"During a manned mission to Mars, Astronaut MarkWatney is presumed dead after a fierce storm and left behind by hiscrew. But Watney has survived and finds himself stranded and alone onthe hostile planet. With only meager supplies, he must draw upon hisingenuity, wit and spirit to subsist and find a way to signal to Earththat he is alive.", 
     release_date:"2015-10-02", 
     genre_ids:[ 
      18, 
      12, 
      878 
     ], 
     id:286217, 
     original_title:"The Martian", 
     original_language:"en", 
     title:"The Martian", 
     backdrop_path:"/sy3e2e4JwdAtd2oZGA2uUilZe8j.jpg", 
     popularity:27.518041, 
     vote_count:2118, 
     video:false, 
     vote_average:7.63 
     }, 
     { 
     poster_path:"/fqe8JxDNO8B8QfOGTdjh6sPCdSC.jpg", 
     adult:false, 
     overview:"Bountyhunters seek shelter from a raging blizzard and get caught up in aplot of betrayal and deception.", 
     release_date:"2015-12-25", 
     genre_ids:[ 
      53, 
      37, 
      18, 
      9648 
     ], 
     id:273248, 
     original_title:"TheHateful Eight", 
     original_language:"en", 
     title:"The Hateful Eight", 
     backdrop_path:"/sSvgNBeBNzAuKl8U8sP50ETJPgx.jpg", 
     popularity:26.55538, 
     vote_count:603, 
     video:false, 
     vote_average:7.13 
     }, 
     { 
     poster_path:"/xPCNA8zJxyyFKTj47QpvkXHukzB.jpg", 
     adult:false, 
     overview:"During the Cold War, the Soviet Union captures U.S. pilotFrancis Gary Powers after shooting down his U-2 spy plane. Sentencedto 10 years in prison, Powers' only hope is New York lawyer JamesDonovan, recruited by a CIA operative to negotiate his release.Donovan boards a plane to Berlin, hoping to win the young man'sfreedom through a prisoner exchange. If all goes well, the Russianswould get Rudolf Abel, the convicted spy who Donovan defended incourt.", 
     release_date:"2015-10-16", 
     genre_ids:[ 
      53, 
      18 
     ], 
     id:296098, 
     original_title:"Bridge of Spies", 
     original_language:"en", 
     title:"Bridge of Spies", 
     backdrop_path:"/bTgqCfMeBgmkcZr2Zw7xO8WlhzK.jpg", 
     popularity:26.301868, 
     vote_count:455, 
     video:false, 
     vote_average:6.94 
     }, 
     { 
     poster_path:"/kqjL17yufvn9OVLyXYpvtyrFfak.jpg", 
     adult:false, 
     overview:"Anapocalyptic story set in the furthest reaches of our planet, in astark desert landscape where humanity is broken, and most everyone iscrazed fighting for the necessities of life. Within this world existtwo rebels on the run who just might be able to restore order. There'sMax, a man of action and a man of few words, who seeks peace of mindfollowing the loss of his wife and child in the aftermath of thechaos. And Furiosa, a woman of action and a woman who believes herpath to survival may be achieved if she can make it across the desertback to her childhood homeland.", 
     release_date:"2015-05-14", 
     genre_ids:[ 
      53, 
      28, 
      12 
     ], 
     id:76341, 
     original_title:"Mad Max: FuryRoad", 
     original_language:"en", 
     title:"Mad Max: Fury Road", 
     backdrop_path:"/tbhdm8UJAb4ViCTsulYFL3lxMCd.jpg", 
     popularity:24.970694, 
     vote_count:3402, 
     video:false, 
     vote_average:7.49 
     }, 
     { 
     poster_path:"/jjBgi2r5cRt36xF6iNUEhzscEcb.jpg", 
     adult:false, 
     overview:"Twenty-two years after the events of Jurassic Park, IslaNublar now features a fully functioning dinosaur theme park, JurassicWorld, as originally envisioned by John Hammond.", 
     release_date:"2015-06-12", 
     genre_ids:[ 
      28, 
      12, 
      878, 
      53 
     ], 
     id:135397, 
     original_title:"Jurassic World", 
     original_language:"en", 
     title:"Jurassic World", 
     backdrop_path:"/dkMD5qlogeRMiEixC4YNPUvax2T.jpg", 
     popularity:24.494238, 
     vote_count:3628, 
     video:false, 
     vote_average:6.74 
     }, 
     { 
     poster_path:"/nBNZadXqJSdt05SHLqgT0HuC5Gm.jpg", 
     adult:false, 
     overview:"Interstellar chronicles the adventures of a group ofexplorers who make use of a newly discovered wormhole to surpass thelimitations on human space travel and conquer the vast distancesinvolved in an interstellar voyage.", 
     release_date:"2014-11-05", 
     genre_ids:[ 
      12, 
      18, 
      878 
     ], 
     id:157336, 
     original_title:"Interstellar", 
     original_language:"en", 
     title:"Interstellar", 
     backdrop_path:"/xu9zaAevzQ5nnrsXN6JcahLnG4i.jpg", 
     popularity:22.536403, 
     vote_count:4185, 
     video:false, 
     vote_average:8.24 
     }, 
     { 
     poster_path:"/xw1GFKzxjgfm3dQoK1swFcHmfaC.jpg", 
     adult:false, 
     overview:"The modern world holds many secrets, but by far the mostastounding is that witches still live among us; vicious supernaturalcreatures intent on unleashing the Black Death upon the world andputting an end to the human race once and for all. Armies of witchhunters have battled this unnatural enemy for centuries, includingKaulder, a valiant warrior who many years ago slayed the all-powerfulWitch Queen, decimating her followers in the process. In the momentsright before her death, the Queen cursed Kaulder with immortality,forever separating him from his beloved wife and daughter. Today,Kaulder is the last living hunter who has spent his immortal lifetracking down rogue witches, all the while yearning for his long-lostfamily.", 
     release_date:"2015-10-23", 
     genre_ids:[ 
      14, 
      28, 
      12 
     ], 
     id:274854, 
     original_title:"The Last Witch Hunter", 
     original_language:"en", 
     title:"The Last Witch Hunter", 
     backdrop_path:"/o6saqjLAgKpczr0yhJkEI9fNwN7.jpg", 
     popularity:21.925333, 
     vote_count:282, 
     video:false, 
     vote_average:5.49 
     }, 
     { 
     poster_path:"/5JU9ytZJyR3zmClGmVm9q4Geqbd.jpg", 
     adult:false, 
     overview:"The yearis 2029. John Connor, leader of the resistance continues the waragainst the machines. At the Los Angeles offensive, John's fears ofthe unknown future begin to emerge when TECOM spies reveal a new plotby SkyNet that will attack him from both fronts; past and future, andwill ultimately change warfare forever.", 
     release_date:"2015-07-01", 
     genre_ids:[ 
      878, 
      28, 
      53, 
      12 
     ], 
     id:87101, 
     original_title:"TerminatorGenisys", 
     original_language:"en", 
     title:"Terminator Genisys", 
     backdrop_path:"/bIlYH4l2AyYvEysmS2AOfjO7Dn8.jpg", 
     popularity:20.298683, 
     vote_count:1656, 
     video:false, 
     vote_average:6.14 
     }, 
     { 
     poster_path:"/q0R4crx2SehcEEQEkYObktdeFy.jpg", 
     adult:false, 
     overview:"Minions Stuart, Kevin and Bob are recruited by ScarletOverkill, a super-villain who, alongside her inventor husband Herb,hatches a plot to take over the world.", 
     release_date:"2015-07-10", 
     genre_ids:[ 
      10751, 
      16, 
      12, 
      35 
     ], 
     id:211672, 
     original_title:"Minions", 
     original_language:"en", 
     title:"Minions", 
     backdrop_path:"/uX7LXnsC7bZJZjn048UCOwkPXWJ.jpg", 
     popularity:19.456371, 
     vote_count:2105, 
     video:false, 
     vote_average:6.7 
     }, 
     { 
     poster_path:"/vQ7oVX2j7BnMDYyzuFeG1epqvGb.jpg", 
     adult:false, 
     overview:"70-year-old widower Ben Whittaker has discovered that retirementisn't all it's cracked up to be. Seizing an opportunity to get back inthe game, he becomes a senior intern at an online fashion site,founded and run by Jules Ostin.", 
     release_date:"2015-09-25", 
     genre_ids:[ 
      35 
     ], 
     id:257211, 
     original_title:"The Intern", 
     original_language:"en", 
     title:"The Intern", 
     backdrop_path:"/nyl1fNn9JguXGTtDl8tES75fSF8.jpg", 
     popularity:18.867295, 
     vote_count:491, 
     video:false, 
     vote_average:7.05 
     }, 
     { 
     poster_path:"/yIVnNriiyl522hk3LFLJrrMovhP.jpg", 
     adult:false, 
     overview:"The truestory of Whitey Bulger, the brother of a state senator and the mostinfamous violent criminal in the history of South Boston, who becamean FBI informant to take down a Mafia family invading his turf.", 
     release_date:"2015-09-18", 
     genre_ids:[ 
      80, 
      18 
     ], 
     id:261023, 
     original_title:"Black Mass", 
     original_language:"en", 
     title:"BlackMass", 
     backdrop_path:"/yU0v8xNqMeCOTo4exyxsNp7N7Kw.jpg", 
     popularity:18.190746, 
     vote_count:403, 
     video:false, 
     vote_average:5.96 
     }, 
     { 
     poster_path:"/vgAHvS0bT3fpcpnJqT6uDTUsHTo.jpg", 
     adult:false, 
     overview:"Immediately after the events of The Desolation of Smaug,Bilbo and the dwarves try to defend Erebor's mountain of treasure fromothers who claim it: the men of the ruined Laketown and the elves ofMirkwood. Meanwhile an army of Orcs led by Azog the Defiler ismarching on Erebor, fueled by the rise of the dark lord Sauron.Dwarves, elves and men must unite, and the hope for Middle-Earth fallsinto Bilbo's hands.", 
     release_date:"2014-12-17", 
     genre_ids:[ 
      12, 
      14 
     ], 
     id:122917, 
     original_title:"The Hobbit: The Battle of the FiveArmies", 
     original_language:"en", 
     title:"The Hobbit: The Battle ofthe Five Armies", 
     backdrop_path:"/qhH3GyIfAnGv1pjdV3mw03qAilg.jpg", 
     popularity:16.720462, 
     vote_count:2343, 
     video:false, 
     vote_average:7.14 
     }, 
     { 
     poster_path:"/D6e8RJf2qUstnfkTslTXNTUAlT.jpg", 
     adult:false, 
     overview:"Armed with the astonishing ability to shrink inscale but increase in strength, con-man Scott Lang must embrace hisinner-hero and help his mentor, Dr. Hank Pym, protect the secretbehind his spectacular Ant-Man suit from a new generation of toweringthreats. Against seemingly insurmountable obstacles, Pym and Lang mustplan and pull off a heist that will save the world.", 
     release_date:"2015-07-17", 
     genre_ids:[ 
      878, 
      28, 
      12 
     ], 
     id:102899, 
     original_title:"Ant-Man", 
     original_language:"en", 
     title:"Ant-Man", 
     backdrop_path:"/kvXLZqY0Ngl1XSw7EaMQO0C1CCj.jpg", 
     popularity:16.448005, 
     vote_count:2414, 
     video:false, 
     vote_average:6.88 
     }, 
     { 
     poster_path:"/nXXI1MCJ0ugMetJ5Qn7ofDXANxf.jpg", 
     adult:false, 
     overview:"Suave,charming and volatile, Reggie Kray and his unstable twin brotherRonnie start to leave their mark on the London underworld in the1960s. Using violence to get what they want, the siblings orchestraterobberies and murders while running nightclubs and protection rackets.With police Detective Leonard "   Nipper" Read hot on their heels, 
     thebrothers continue their rapid rise to power and achieve tabloidnotoriety.", 
     release_date:"2015-09-09", 
     genre_ids:[ 
      80, 
      53 
     ], 
     id:276907, 
     original_title:"Legend", 
     original_language:"en", 
     title:"Legend", 
     backdrop_path:"/zAZdEjBlQSywUjY2TQKso1aNvwN.jpg", 
     popularity:15.78096, 
     vote_count:155, 
     video:false, 
     vote_average:6.75 
     }, 
     { 
     poster_path:"/vlTPQANjLYTebzFJM1G4KeON0cb.jpg", 
     adult:false, 
     overview:"Thomas and his fellow Gladers face their greatestchallenge yet: searching for clues about the mysterious and powerfulorganization known as WCKD. Their journey takes them to the Scorch, adesolate landscape filled with unimaginable obstacles. Teaming up withresistance fighters, the Gladers take on WCKD’s vastly superior forcesand uncover its shocking plans for them all.", 
     release_date:"2015-09-18", 
     genre_ids:[ 
      53, 
      28, 
      878 
     ], 
     id:294254, 
     original_title:"Maze Runner: The Scorch Trials", 
     original_language:"en", 
     title:"Maze Runner: The Scorch Trials", 
     backdrop_path:"/iapRFMGKvN9tsjqPlN7MIDTCezG.jpg", 
     popularity:15.521757, 
     vote_count:1006, 
     video:false, 
     vote_average:6.56 
     }, 
     { 
     poster_path:"/cWERd8rgbw7bCMZlwP207HUXxym.jpg", 
     adult:false, 
     overview:"KatnissEverdeen reluctantly becomes the symbol of a mass rebellion againstthe autocratic Capitol.", 
     release_date:"2014-11-21", 
     genre_ids:[ 
      878, 
      12, 
      53 
     ], 
     id:131631, 
     original_title:"The Hunger Games:Mockingjay - Part 1", 
     original_language:"en", 
     title:"The HungerGames: Mockingjay - Part 1", 
     backdrop_path:"/fUn5I5f4069vwGFEEvA3HXt9xPP.jpg", 
     popularity:15.521613, 
     vote_count:2426, 
     video:false, 
     vote_average:6.86 
     }, 
     { 
     poster_path:"/aAmfIX3TT40zUHGcCKrlOZRKC7u.jpg", 
     adult:false, 
     overview:"Growingup can be a bumpy road, and it's no exception for Riley, who isuprooted from her Midwest life when her father starts a new job in SanFrancisco. Like all of us, Riley is guided by her emotions - Joy,Fear, Anger, Disgust and Sadness. The emotions live in Headquarters,the control center inside Riley's mind, where they help advise herthrough everyday life. As Riley and her emotions struggle to adjust toa new life in San Francisco, turmoil ensues in Headquarters. AlthoughJoy, Riley's main and most important emotion, tries to keep thingspositive, the emotions conflict on how best to navigate a new city,house and school.", 
     release_date:"2015-06-19", 
     genre_ids:[ 
      35, 
      16, 
      10751 
     ], 
     id:150540, 
     original_title:"Inside Out", 
     original_language:"en", 
     title:"Inside Out", 
     backdrop_path:"/szytSpLAyBh3ULei3x663mAv5ZT.jpg", 
     popularity:14.92858, 
     vote_count:2415, 
     video:false, 
     vote_average:8.04 
     } 
    ], 
    total_results:252862, 
    total_pages:12644 
} 

public void parsePopularMovieJson(String json) throws JSONException { 
    JSONObject popularMovies = new JSONObject(json); 
    JSONArray results = popularMovies.getJSONArray("results"); 

    for (int i = 0; i < results.length(); i++) { 
     JSONObject currentMovie = results.getJSONObject(i); 
     Movie movie = new Movie(); 

     movie.setPosterPath(currentMovie.getString("poster_path")); 
     movie.setOverView(currentMovie.getString("overview")); 
     movie.setReleaseDate(currentMovie.getString("release_date")); 
     movie.setOriginalTitle(currentMovie.getString("original_title")); 
     movie.setVoteAverage(currentMovie.getDouble("vote_average")); 
     mImageUrl[i] = movie.getPosterPath(); 
     movies.add(movie); 
    } 
} 

По моему отладчику, входя в цикл объекта в popularMovies равно всю строку и результаты равно основной массив внутри строки. В какой-то момент во время первой итерации цикла for я получаю сообщение об ошибке рядом с популярными новостями или результатами, указанными Object has been collected Cannot evaluate JSONObject(Array).toString().

Я отлаживал это часами и не могу понять, почему это происходит. Если кто-то мог бы прояснить, почему это происходит в середине цикла for, было бы очень полезно! Благодаря!

[РЕШЕНИЕ]: JSON был неправильно отформатирован. Спасибо, что указали это. Извиняюсь за мое невежество, я новичок в формате JSON!

+0

, какой тип ошибки вы получили? – sasikumar

+0

На какой линии возникает проблема? –

+0

Это то, что странно, это никогда не одна конкретная строка. Иногда это будет на releaseDate в следующем отладочном прогоне, который будет на voteAverage. Один отладочный запуск - это массив результатов, который появляется с ошибкой, а другой будет объектом popularMovies. В конечном итоге метод выдает исключение JSONException и завершает работу. –

ответ

2

использование Java Исключение точки останова Ctrl + Shift + f8 и включить исключение останова

+0

Извините, у меня нет репутации, чтобы прокомментировать, почему вы отправили ответ –

+0

попробуйте отладки с использованием точки исключения исключения и см. –

+0

После первой итерации он выходит из цикла for, бросая исключение JSON «Конец ввода с символом 0 из». Согласно всем остальным сообщениям по этому вопросу это указывает на пустой ответ, но я точно знаю, что мой ответ не пуст. –

Смежные вопросы