0

我成功地获得了电影的名称和年份,但不知何故没有得到概要。据我了解对象的形状,它们应该可以以相同的方式到达:

JSONObject resultOBJ = new JSONObject(result);
Log.v("hhhh",resultOBJ.toString());
JSONArray movArr = resultOBJ.getJSONArray("movies"); 
JSONObject movOBJ =movArr.getJSONObject(0);
String title = movOBJ.getString("title");
String synop = movOBJ.getString("synopsis");

nameView.setText(title);
synopView.setText(synop);

我收到的对象看起来像这样(无格式):

{
    "total": 1,
    "movies": [
        {
            "critics_consensus": "Deftly blending comedy, ...",
            "id": "770672122",
            "mpaa_rating": "G",
            "ratings": {
                "audience_rating": "Upright",
                "audience_score": 87,
                "critics_rating": "Certified Fresh",
                "critics_score": 99
            },
            "release_dates": {
                "dvd": "2010-11-02",
                "theater": "2010-06-18"
            },
            "runtime": 103,
            "title": "Toy Story 3",
            "year": 2010,
            "synopsis": "Pixar returns to their first success with ...

等等……

4

1 回答 1

1

我举了你的例子(复制/粘贴),为 Json 关闭了一些门,得到了正确的结果:

public static void main(String[] args) throws JSONException  {

    String result = "{" + 
            "    \"total\": 1," + 
            "    \"movies\": [" + 
            "        {" + 
            "            \"id\": \"770672122\"," + 
            "            \"title\": \"Toy Story 3\"," + 
            "            \"year\": 2010," + 
            "            \"mpaa_rating\": \"G\"," + 
            "            \"runtime\": 103," + 
            "            \"critics_consensus\": \"Deftly blending comedy,adventure, and honest emotion, Toy Story 3 is a rare second sequel that really works.\"," + 
            "            \"release_dates\": {" + 
            "                \"theater\": \"2010-06-18\"," + 
            "                \"dvd\": \"2010-11-02\"" + 
            "            }," + 
            "            \"ratings\": {" + 
            "                \"critics_rating\": \"Certified Fresh\"," + 
            "                \"critics_score\": 99," + 
            "                \"audience_rating\": \"Upright\"," + 
            "                \"audience_score\": 87" + 
            "            }," + 
            "            \"synopsis\": \"Pixar returns to their first success with Toy Story 3. The movie begins with Andy leaving for college and donating his beloved toys -- including Woody (Tom Hanks) and Buzz (Tim Allen) -- to a daycare. While the crew meets new friends, including Ken (Michael Keaton), they soon grow to hate their new surroundings and plan an escape. The film was directed by Lee Unkrich from a script co-authored by Little Miss Sunshine scribe Michael Arndt. ~ Perry Seibert, Rovi\"" + 
            "        }" + 
            "    ]" + 
            "}";


    JSONObject resultOBJ = new JSONObject(result);

    JSONArray movArr = resultOBJ.getJSONArray("movies"); 

    JSONObject movOBJ =movArr.getJSONObject(0);
    String title = movOBJ.getString("title");
    String synop = movOBJ.getString("synopsis");
    System.out.println(synop); 
}

输出:

皮克斯凭借《玩具总动员 3》重回他们的第一次成功。电影开始于安迪上大学并将他心爱的玩具——包括伍迪(汤姆汉克斯饰)和巴兹(蒂姆艾伦饰)——捐赠给托儿所。当船员们结识了包括肯(迈克尔·基顿饰)在内的新朋友时,他们很快就开始讨厌他们的新环境并计划逃跑。这部电影由李·昂克里奇执导,剧本由阳光小美女编剧迈克尔·阿恩特共同撰写。〜佩里塞伯特,罗维

于 2013-11-05T23:16:20.113 回答