Java 如何在android中解析单个对象中的嵌套json数组

Java 如何在android中解析单个对象中的嵌套json数组,java,android,json,Java,Android,Json,我有一个json,它有许多嵌套的JSONARRAY。下面是片段 { "location": [ { "name": "Perth", "conferencelocation": [ { "locationname":"Stage 1" , "guests": [

我有一个json,它有许多嵌套的JSONARRAY。下面是片段

{
    "location": [ 
        { 
            "name": "Perth", 
            "conferencelocation": [
                {
                    "locationname":"Stage 1" ,
                    "guests": [
                        {
                            "guestid":"4074513426041094",
                            "guestname":"Keegan Connor Tracy",
                            "time":"9am",
                            "largeimg":"http://ozcomiccon.com/images/banner/Keegan.jpg",
                            "smallimg":"http://ozcomiccon.com/images/banner/Keeganresized.jpg",
                            "biotext": "Born in Windsor, Ontario, Canada, Tracy attended Wilfrid Laurier University in Waterloo, Ontario, Canada, where she orginally studied business. She later switched to psychology. She spent a year in Europe working in Dublin, Paris and Nice, where she was supposed to be completing her 4th year of study. She later returned to WLU to finish her degree. She moved to Vancouver, B.C. where she has had all of her acting jobs.",
                            "autographs":"$30 each (an 8x10 photograph will be included with each signature, or you may choose to have an appropriate personal item signed).",
                            "photographs":"Photo with Keegan $40.",
                            "genre":"acting",
                            "links": [
                                {"linkname":"Twitter", "url":"https://twitter.com/keegolicious" },
                                {"linkname":"IMDB", "url":"http://www.imdb.com/name/nm0870535/" }
                            ]
                        },
                        {
                            "guestid":"1054713366041913",
                            "guestname":"Matthew Clark",
                            "time":"10am",
                            "largeimg":"http://ozcomiccon.com/images/banner/matthewclark.jpg",
                            "smallimg":"http://ozcomiccon.com/images/banner/matthewclarkresized.jpg",
                            "biotext": "Matthew Clark is a comic book artist living and working in Portland, Oregon. Having worked on art of some of the most well-known DC characters in comic book history, he  recently did pencils for DC’s latest version of the Doom Patrol. Matthew is currently working on Ghost Rider for Marvel Comics, with whom he has signed an exclusive two-year deal.<br /><br />Matthew has lived in Portland for the past 13 years, just above an art gallery in the heart of downtown. He loves to walk around this fair city (mainly because he sold his car and needed to force himself to exercise). He’s a native Oregonian and that’s saying something.  For the past 11 years he’s met Greg Rucka for coffee every Wednesday pretty much without fail at the same place (we pretty much carved our names in the table). Matthew was also one of the original founders of Mercury Studio (now Periscope Studio); he got his start at Studiosaurus.<br /><br />He still reads comics, loves what he does, and works very hard. Loves to meet new people, but is really quiet (and has great hair).",
                            "autographs":"Complimentary at guest's discretion.(Twitter)",
                            "photographs":"",
                            "genre":"comic",
                            "links": [
                                {"linkname":"Website", "url":"http://www.matthewclarkartist.com/" },
                                {"linkname":"Twitter", "url":"https://twitter.com/emceeartist" }
                            ]
                        }
                    ]
                },
                {
                    "locationname":"Stage 2" ,
                    "guests": [
                        {
                            "guestid":"106146633306036834",
                            "guestname":"Sean Williams",
                            "time":"8am",
                            "largeimg":"http://ozcomiccon.com/images/banner/seanwilliams.jpg",
                            "smallimg":"http://ozcomiccon.com/images/banner/seanwilliamsresized.jpg",
                            "biotext": "Sean Williams was born in the dry, flat lands of South Australia, where he still lives with his wife and family. He has been called many things in his time, including “the premier Australian speculative fiction writer of the age†(Aurealis), the “Emperor of Sci-Fi†(Adelaide Advertiser), and the “King of Chameleons†(Australian Book Review) for the diversity of his output.  That award-winning output includes thirty-five novels for readers all ages, seventy-five short stories across numerous genres, the odd published poem, and even a sci-fi musical.<br /><br />He is a multiple recipient of the Aurealis and Ditmar Awards in multiple categories and has been nominated for the Philip K. Dick Award, the Seiun Award, and the William Atheling Jr. Award for criticism. He received the “SA Great†Literature Award in 2000 and the Peter McNamara Award for contributions to Australian speculative fiction in 2008.<br /><br />On the sci-fi front, he is best-known internationally for his original award-winning space opera series as well as several novels set in the Star Wars universe, many co-written with fellow-Adelaidean Shane Dix.  These include the Astropolis, Evergence, Orphans and Geodesica series, and the computer game tie-in The Force Unleashed–the first such adaptation ever to debut at #1 on the New York Times bestseller list.  A series for young readers, The Fixers, pitted an increasingly lost protagonist against zombies, cyborgs, and vampires across numerous universes. His most recent releases in the Star Wars universe are The Old Republic: Fatal Alliance and The Force Unleashed II.",
                            "autographs":"Complimentary at guest's discretion.",
                            "photographs":"",
                            "genre":"comic",
                            "links": [
                                {"linkname":"website", "url":"http://www.seanwilliams.com" }
                            ]
                        },
                        {
                            "guestid":"17148603639603876",
                            "guestname":"Richard Dean Anderson",
                            "time":"10am",
                            "largeimg":"http://ozcomiccon.com/images/banner/richarddeananderson.jpg",
                            "smallimg":"http://ozcomiccon.com/images/banner/richarddeanandersonresized.jpg",
                            "biotext": "Richard Dean Anderson is probably best known as MacGyver, the clever and inventive nonviolent hero who solved problems in his own unique way for seven successful seasons on ABC. In his roles before and since, this gifted actor has continued to demonstrate his remarkable talent and versatility.<br /><br />Richard was born on January 23, 1950 in Minneapolis, Minnesota. His father, Stuart Anderson, taught English, drama, and humanities at a local high school, and is an accomplished jazz bassist. His mother, Jocelyn, is an artist, talented in both painting and sculpture. Richard is the eldest of four sons. He and his brothers, Jeffrey Scott, Thomas John, and James Stuart, grew up in the Minneapolis suburb of Roseville, where Richard developed early interests in sports, the arts, music, and acting.<br /><br />Like many boys growing up in Minnesota, Richard dreamed of becoming a professional hockey player. However, at the age of 16, he broke both arms, in separate accidents three weeks apart, while playing in high school hockey games. He put aside his dreams of playing professionally, though he still harbors a deep love for the sport. Richard talks of his restlessness growing up, his early desire to explore, and his adventures hitchhiking and hopping freight trains. At the age of 17, he took a 5641 mile bicycle trip from his home in Minnesota through Canada and Alaska, an experience which was sparked by his sense of adventure and discovery, but which also gave him a more centered sense of direction.",
                            "autographs":"Autograph from Richard $50.",
                            "photographs":"Photograph with Richard $80. SG1 double shot with Richard and Teryl Rothery $150. SG1 triple shot with Richard, Teryl Rothery and Corin Nemec $200.",
                            "genre":"acting",
                            "links": [
                                {"linkname":"Website", "url":"http://www.rdanderson.com/" },
                                {"linkname":"Twitter", "url":"https://twitter.com/andersonrdean" }
                            ]
                        }
                    ]
                }
            ]
        }
    ]

有人能告诉我我犯了什么错误吗?

下面是我的解决方案:

JSONObject first = new JSONObject(mResponse);

JSONArray locArr = first.getJSONArray("location"); // contains one object
JSONObject locArrObj = locArr.getJSONObject(0); // cotains one "out" array

JSONArray conferenceLocArr = locArrObj.getJSONArray("conferencelocation");
// this array has two objects and each object has array
JSONObject o = null;
JSONArray arr = null;

for (int i = 0; i < conferenceLocArr.length(); i++) {
   o = conferenceLocArr.getJSONObject(i); // it has one array
   arr = o.getJSONArray("guests");
   //  do your work with Stage 1 and guests
   // and for second object for Stage 2 and guests.
}
JSONObject first=新的JSONObject(mResponse);
JSONArray locArr=first.getJSONArray(“位置”);//包含一个对象
JSONObject locArrObj=locArr.getJSONObject(0);//cotains一个“out”数组
JSONArray conferenceLocArr=locArrObj.getJSONArray(“conferencelocation”);
//此数组有两个对象,每个对象有一个数组
JSONObject o=null;
JSONArray arr=null;
对于(int i=0;i//与第一阶段和客人一起工作
//第二个目标是第二阶段和客人。
}

你能详细解释一下吗?我想它离我的目的地很近,谢谢:)所以你需要“一步一步”地使用JSON。A不要认为解决方案太复杂。您必须检查JSON文件,仔细阅读并查看括号<代码>{括号表示JSONObject,以
}
结尾<代码>[括号表示JSONArray,以
]
结束。与第1阶段和来宾以及第2阶段和来宾一起工作。这一行对我来说不清楚,我是json解析的新手,如果你能描述一下,那会很有帮助。所以你想解析json,你知道格式,这不好,不是吗?例如,我建议你阅读一些关于wikipedia上JSON的内容,然后用简单得多的JSON制作一些应用程序,然后看看我的解决方案。我知道JSON,但对嵌套jsonarray没有太多经验
JSONObject first = new JSONObject(mResponse);

JSONArray locArr = first.getJSONArray("location"); // contains one object
JSONObject locArrObj = locArr.getJSONObject(0); // cotains one "out" array

JSONArray conferenceLocArr = locArrObj.getJSONArray("conferencelocation");
// this array has two objects and each object has array
JSONObject o = null;
JSONArray arr = null;

for (int i = 0; i < conferenceLocArr.length(); i++) {
   o = conferenceLocArr.getJSONObject(i); // it has one array
   arr = o.getJSONArray("guests");
   //  do your work with Stage 1 and guests
   // and for second object for Stage 2 and guests.
}