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 に答える