我使用这个教程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的情况下不起作用!!
请告诉我如何解决这个问题。
您没有得到正确的节点。获取适当的节点并进行映射。
另一种解决方法是为实体创建映射,并可以使用convert函数并获取媒体url。
{
name : 'mediaUrl',
type : 'string',
convert : function(v, record) {
var entities= record.get('entities');
var meridaUrl= entities.media[0].media_url;
return meridaUrl;
}},
试试这个,让我知道
解决方案如下:
entities.media[0].media_url