android:如何读取json数据

时间:2013-05-20 12:18:44

标签: android json arrays

你可以帮我解释一下如何阅读这些数据吗? 我收到了一个字符串中的JSON数据。但是无法解析它。 请帮助。

这是我的json:

{
   "951":{
      "title":{
         "en":"Vida Crew",
         "es":"Vida Personal"
      },
      "sub":{
         "1345":{
            "title":{
               "en":"Ana Dominguez",
               "es":"Ana Dominguez"
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=1345",
            "djid":"1345",
            "img":"http://www.vidamedia.net/wp-content/uploads/2013/04/Ana-Dominguez-300x300-150x150.jpg",
            "imgname":"Ana-Dominguez-300x300-150x150.jpg"
         },
         "488":{
            "title":{
               "en":"Angelica Bastida",
               "es":"Angelica Bastida"
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=488",
            "djid":"488",
            "img":"http://www.vidamedia.net/wp-content/uploads/2013/03/anglicathumb6-150x150.jpg",
            "imgname":"anglicathumb6-150x150.jpg"
         },
         "1349":{
            "title":{
               "en":"Biankita Juarez",
               "es":"Biankita Juarez"
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=1349",
            "djid":"1349",
            "img":"http://www.vidamedia.net/wp-content/uploads/2013/04/Bianca-Juarez-300x300-150x150.jpg",
            "imgname":"Bianca-Juarez-300x300-150x150.jpg"
         },
         "479":{
            "title":{
               "en":"Deisi Sandoval",
               "es":"Deisi Sandoval"
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=479",
            "djid":"479",
            "img":"http://www.vidamedia.net/wp-content/uploads/2013/03/Deisi-Sandoval2-150x150.jpg",
            "imgname":"Deisi-Sandoval2-150x150.jpg"
         },
         "489":{
            "title":{
               "en":"Gonzalo Cerna",
               "es":"Gonzalo Cerna"
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=489",
            "djid":"489",
            "img":"http://www.vidamedia.net/wp-content/uploads/2013/03/Gonzalo-Cerna2-150x150.jpg",
            "imgname":"Gonzalo-Cerna2-150x150.jpg"
         },
         "485":{
            "title":{
               "en":"Grant",
               "es":"Grant"
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=485",
            "djid":"485",
            "img":"http://www.vidamedia.net/wp-content/uploads/2013/03/Grant3-150x150.jpg",
            "imgname":"Grant3-150x150.jpg"
         },
         "481":{
            "title":{
               "en":"Guadalupe Esquer",
               "es":"Guadalupe Esquer"
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=481",
            "djid":"481",
            "img":"http://www.vidamedia.net/wp-content/uploads/2013/03/Guadalupe-Esquer2-150x150.jpg",
            "imgname":"Guadalupe-Esquer2-150x150.jpg"
         },
         "486":{
            "title":{
               "en":"Lili Sandoval",
               "es":"Lili Sandoval"
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=486",
            "djid":"486",
            "img":"http://www.vidamedia.net/wp-content/uploads/2013/03/Lili-Sandoval2-150x150.jpg",
            "imgname":"Lili-Sandoval2-150x150.jpg"
         },
         "478":{
            "title":{
               "en":"L\u2019Gallo D\u2019Zakatekaz",
               "es":"L\u2019Gallo D\u2019Zakatekaz"
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=478",
            "djid":"478",
            "img":"http://www.vidamedia.net/wp-content/uploads/2013/03/LGallo-DZakatekaz2-150x150.png",
            "imgname":"LGallo-DZakatekaz2-150x150.png"
         },
         "480":{
            "title":{
               "en":"Orlando Evans",
               "es":"Orlando Evans"
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=480",
            "djid":"480",
            "img":"http://www.vidamedia.net/wp-content/uploads/2013/03/Orlando-Evans2-150x150.jpg",
            "imgname":"Orlando-Evans2-150x150.jpg"
         },
         "482":{
            "title":{
               "en":"Pedro \"El Valedor\" ",
               "es":"Pedro \"El Valedor\" "
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=482",
            "djid":"482",
            "img":"http://www.vidamedia.net/wp-content/uploads/2013/03/Pedro-El-ValedorRamirez2-150x150.jpg",
            "imgname":"Pedro-El-ValedorRamirez2-150x150.jpg"
         },
         "484":{
            "title":{
               "en":"Rosy Sandoval",
               "es":"Rosy Sandoval"
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=484",
            "djid":"484",
            "img":"http://www.vidamedia.net/wp-content/uploads/2013/03/Rosy-Sandoval2-150x150.jpg",
            "imgname":"Rosy-Sandoval2-150x150.jpg"
         },
         "487":{
            "title":{
               "en":"Shawn Meade",
               "es":"Shawn Meade"
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=487",
            "djid":"487",
            "img":"http://www.vidamedia.net/wp-content/uploads/2013/03/Shawn-with-Joan-Jett-Web-e1342661118464-150x150.jpg",
            "imgname":"Shawn-with-Joan-Jett-Web-e1342661118464-150x150.jpg"
         },
         "483":{
            "title":{
               "en":"Teri La Rue",
               "es":"Teri La Rue"
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=483",
            "djid":"483",
            "img":"http://www.vidamedia.net/wp-content/uploads/2013/03/Teri-e1336088610838-150x150.jpg",
            "imgname":"Teri-e1336088610838-150x150.jpg"
         }
      }
   },
   "950":{
      "title":{
         "en":"Guest DJs",
         "es":"DJs invitados"
      },
      "sub":{
         "1375":{
            "title":{
               "en":" J-Skillz, Jonathan Ramirez",
               "es":" J-Skillz, Jonathan Ramirez"
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=1375",
            "djid":"1375",
            "img":"http://www.vidamedia.net/wp-content/uploads/2013/04/Jonathan-Ramirez-150x150.jpg",
            "imgname":"Jonathan-Ramirez-150x150.jpg"
         },
         "493":{
            "title":{
               "en":"Dee J Unkut",
               "es":"Dee J Unkut"
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=493",
            "djid":"493",
            "img":"",
            "imgname":""
         },
         "492":{
            "title":{
               "en":"DJ MonsterMack",
               "es":"DJ MonsterMack"
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=492",
            "djid":"492",
            "img":"http://www.vidamedia.net/wp-content/uploads/2013/03/DJ-MonsterMack2-150x150.jpg",
            "imgname":"DJ-MonsterMack2-150x150.jpg"
         },
         "491":{
            "title":{
               "en":"DJ Tony Piedra",
               "es":"DJ Tony Piedra"
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=491",
            "djid":"491",
            "img":"http://www.vidamedia.net/wp-content/uploads/2013/03/DJ-Tony-Piedra2-150x150.jpg",
            "imgname":"DJ-Tony-Piedra2-150x150.jpg"
         },
         "490":{
            "title":{
               "en":"Empresa Valdivia",
               "es":"Empresa Valdivia"
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=490",
            "djid":"490",
            "img":"http://www.vidamedia.net/wp-content/uploads/2013/03/Empresa-Valdivia2-150x150.jpg",
            "imgname":"Empresa-Valdivia2-150x150.jpg"
         },
         "1356":{
            "title":{
               "en":"Original Banda El Limon, Thornton, Primer Jaripeo Baile Del Ano, Domingo 19 de Mayo 2013",
               "es":"Original Banda El Limon, Thornton, Primer Jaripeo Baile Del Ano, Domingo 19 de Mayo 2013"
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=1356",
            "djid":"1356",
            "img":"http://www.vidamedia.net/wp-content/uploads/2013/04/JR-Universal-USA-Primer-Jaripeo-Baile-flyer-150x150.jpg",
            "imgname":"JR-Universal-USA-Primer-Jaripeo-Baile-flyer-150x150.jpg"
         }
      }
   },
   "949":{
      "title":{
         "en":"Up and Coming DJs",
         "es":"Arriba y DJs Coming"
      },
      "sub":{
         "497":{
            "title":{
               "en":"B.J. Cobbledick",
               "es":"B.J. Cobbledick"
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=497",
            "djid":"497",
            "img":"",
            "imgname":""
         },
         "498":{
            "title":{
               "en":"DJ Max Mixx",
               "es":"DJ Max Mixx"
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=498",
            "djid":"498",
            "img":"http://www.vidamedia.net/wp-content/uploads/2013/03/DJ-Max-Mixx2-150x150.jpg",
            "imgname":"DJ-Max-Mixx2-150x150.jpg"
         },
         "496":{
            "title":{
               "en":"Kelly \"Hammer Time\" Howlett",
               "es":"Kelly \"Hammer Time\" Howlett"
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=496",
            "djid":"496",
            "img":"http://www.vidamedia.net/wp-content/uploads/2013/03/DJ-Hammertime-300x300-150x150.jpg",
            "imgname":"DJ-Hammertime-300x300-150x150.jpg"
         },
         "494":{
            "title":{
               "en":"Rusty Kuntz",
               "es":"Rusty Kuntz"
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=494",
            "djid":"494",
            "img":"http://www.vidamedia.net/wp-content/uploads/2013/03/Rusty-Kuntz2-150x150.jpg",
            "imgname":"Rusty-Kuntz2-150x150.jpg"
         },
         "495":{
            "title":{
               "en":"Tiny Kox",
               "es":"Tiny Kox"
            },
            "link":"http://www.vidamedia.net/getxmlgeneral.php?action=djpage&djId=495",
            "djid":"495",
            "img":"http://www.vidamedia.net/wp-content/uploads/2013/03/Tiny-Kox2-150x150.jpg",
            "imgname":"Tiny-Kox2-150x150.jpg"
         }
      }
   }
}

1 个答案:

答案 0 :(得分:0)

使用您的JSON字符串初始化JSONObject:

JSONObject json = new JSONObject("<your json string here>");

然后根据其字段顺序读取它:

boolean someBoolean = json.getBoolean("<boolean field>");
JSONObject nestedJsonObject = json.getJSONObject("<json object field>");
....

还要确保在无法解析输入的情况下捕获异常。