Sencha Touch 2.4 и твиттер API 1.1, как JSON в магазине

1

Я создал json-магазин в sencha touch, используя этот учебник https://www.youtube.com/watch?v=GQaPt-gQVRI

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 !!

пожалуйста, дайте мне знать, как решить эту проблему.

Теги:
twitter
sencha-touch-2

2 ответа

0

Вот решение:

entities.media[0].media_url
0

Вы не получаете правильный узел. Получите правильный узел и выполните картографирование.

Другая работа вокруг - вы создаете сопоставление для сущностей и можете использовать функцию преобразования и получать медиа-URL.

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

попробуйте это и дайте мне знать.

  • 0
    tnx, к сожалению, выдается ошибка 'Uncaught ReferenceError: запись не определена' в var entity = record.get ('entity') ;, похоже, идентификатор не определен!
  • 0
    Вы должны определить одно поле в модели с именами сущностей и сопоставить их с вашими сущностями в объекте json. Тогда это будет работать, если у вас возникнут какие-либо проблемы, предоставьте мне фрагмент кода модели, который я изменю и дам вам,

Ещё вопросы

Сообщество Overcoder
Наверх
Меню