Sencha Touch 2.4和twetter api 1.1作为json在商店里

时间:2015-07-30 00:25:39

标签: php json twitter sencha-touch-2

我使用本教程https://www.youtube.com/watch?v=GQaPt-gQVRI

在sencha touch中创建了一个json商店

Json如下所示:

[
{
    "created_at": "Sat Apr 05 20:06:38 +0000 2014",
    "id": 34563456345646,
    "id_str": "5643563456456",
    "text": "My lovely boy: Adrian,  04.04.2014 only 2 hours old!!! http://t.co/1F8MhRa0eH",
    "source": "<a href=\"http: //twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>",
    "truncated": false,
    "in_reply_to_status_id": null,
    "in_reply_to_status_id_str": null,
    "in_reply_to_user_id": null,
    "in_reply_to_user_id_str": null,
    "in_reply_to_screen_name": null,
    "user": {
        "id": 456456,
        "id_str": "4356456",
        "name": "xxxxx",
        "screen_name": "xxxxxxx",
        "location": "",
        "description": "",
        "url": null,
        "entities": {
            "description": {
                "urls": [

                ]
            }
        },
        "protected": false,
        "followers_count": 8,
        "friends_count": 18,
        "listed_count": 0,
        "created_at": "Fri Mar 09 00:08:22 +0000 2012",
        "favourites_count": 1,
        "utc_offset": 7200,
        "time_zone": "Berlin",
        "geo_enabled": false,
        "verified": false,
        "statuses_count": 11,
        "lang": "en",
        "contributors_enabled": false,
        "is_translator": false,
        "is_translation_enabled": false,
        "profile_background_color": "282828",
        "profile_background_image_url": "http://pbs.twimg.com/profile_background_images/577489227/58nipt5bo41ae2tkq02g.jpeg",
        "profile_background_image_url_https": "https://pbs.twimg.com/profile_background_images/577489227/58nipt5bo41ae2tkq02g.jpeg",
        "profile_background_tile": false,
        "profile_image_url": "http://pbs.twimg.com/profile_images/1882584072/image_normal.jpg",
        "profile_image_url_https": "https://pbs.twimg.com/profile_images/1882584072/image_normal.jpg",
        "profile_link_color": "FC0243",
        "profile_sidebar_border_color": "D0F2DD",
        "profile_sidebar_fill_color": "D3DFD1",
        "profile_text_color": "D7CAC3",
        "profile_use_background_image": true,
        "has_extended_profile": false,
        "default_profile": false,
        "default_profile_image": false,
        "following": false,
        "follow_request_sent": false,
        "notifications": false
    },
    "geo": null,
    "coordinates": null,
    "place": null,
    "contributors": null,
    "is_quote_status": false,
    "retweet_count": 0,
    "favorite_count": 0,
    "entities": {
        "hashtags": [

        ],
        "symbols": [

        ],
        "user_mentions": [

        ],
        "urls": [

        ],
        "media": [
            {
                "id": 452537815365333000,
                "id_str": "452537815365332992",
                "indices": [
                    55,
                    77
                ],
                "media_url": "http://pbs.twimg.com/media/Bke8vtRIMAAB2QK.jpg",
                "media_url_https": "https://pbs.twimg.com/media/Bke8vtRIMAAB2QK.jpg",
                "url": "http://t.co/1F8MhRa0eH",
                "display_url": "pic.twitter.com/1F8MhRa0eH",
                "expanded_url": "http://twitter.com/xxxxxx/status/452537817038848001/photo/1",
                "type": "photo",
                "sizes": {
                    "small": {
                        "w": 340,
                        "h": 255,
                        "resize": "fit"
                    },
                    "medium": {
                        "w": 600,
                        "h": 450,
                        "resize": "fit"
                    },
                    "thumb": {
                        "w": 150,
                        "h": 150,
                        "resize": "crop"
                    },
                    "large": {
                        "w": 1024,
                        "h": 768,
                        "resize": "fit"
                    }
                }
            }
        ]
    },
    "extended_entities": {
        "media": [
            {
                "id": 452537815365333000,
                "id_str": "452537815365332992",
                "indices": [
                    55,
                    77
                ],
                "media_url": "http://pbs.twimg.com/media/Bke8vtRIMAAB2QK.jpg",
                "media_url_https": "https://pbs.twimg.com/media/Bke8vtRIMAAB2QK.jpg",
                "url": "http://t.co/1F8MhRa0eH",
                "display_url": "pic.twitter.com/1F8MhRa0eH",
                "expanded_url": "http://twitter.com/xxxxx/status/452537817038848001/photo/1",
                "type": "photo",
                "sizes": {
                    "small": {
                        "w": 340,
                        "h": 255,
                        "resize": "fit"
                    },
                    "medium": {
                        "w": 600,
                        "h": 450,
                        "resize": "fit"
                    },
                    "thumb": {
                        "w": 150,
                        "h": 150,
                        "resize": "crop"
                    },
                    "large": {
                        "w": 1024,
                        "h": 768,
                        "resize": "fit"
                    }
                }
            }
        ]
    },
    "favorited": false,
    "retweeted": false,
    "possibly_sensitive": false,
    "lang": "en"
}

} ] 但是json数据太复杂了,我在实体中得到了media_url,我在模型中做了一个映射到达其他部分但是在media_url的情况下映射不起作用!!

请让我知道如何解决这个问题。

2 个答案:

答案 0 :(得分:0)

你没有得到合适的节点。获取正确的节点并进行映射。

其他解决方法是为实体创建映射并使用convert函数 并获得媒体网址。

 {
 name : 'mediaUrl',
 type : 'string',
 convert : function(v, record) {
 var entities= record.get('entities');
 var meridaUrl= entities.media[0].media_url;
  return meridaUrl;
  }},

试试这个,让我知道。

答案 1 :(得分:0)

以下是解决方案:

entities.media[0].media_url