我从django后端的API中获取数据,并将数据序列化以获得所需的字段,然后将其发送到前端
该seriliaser
class EventSearchOutputSerialiser(Serializer):
date_time = DateTimeField(source='dates.start.dateTime')
icon = URLField(source='images.0.url', allow_null=True)
event = CharField(source='name')
genre = CharField(source='classifications.0.genre.name')
venue = CharField(source='_embedded.venues.0.name')
字符串
所以基本上我在这里试图从嵌套字段中提取数据。
一个将被传递用于序列化的获取数据的例子。该数据从ticketmaster API获取。
[
{
"name": "Utah Jazz vs. Phoenix Suns",
"type": "event",
"id": "Z7r9jZ1AdJ9uz",
"test": false,
"url": "https://www.ticketmaster.com/event/Z7r9jZ1AdJ9uz",
"locale": "en-us",
"images": [
{
"ratio": "3_2",
"url": "https://s1.ticketm.net/dam/a/a01/dc895acf-863e-4f90-9316-98302e99fa01_1761311_RETINA_PORTRAIT_3_2.jpg",
"width": 640,
"height": 427,
"fallback": false
},
{
"ratio": "3_2",
"url": "https://s1.ticketm.net/dam/a/a01/dc895acf-863e-4f90-9316-98302e99fa01_1761311_ARTIST_PAGE_3_2.jpg",
"width": 305,
"height": 203,
"fallback": false
},
{
"ratio": "4_3",
"url": "https://s1.ticketm.net/dam/a/a01/dc895acf-863e-4f90-9316-98302e99fa01_1761311_CUSTOM.jpg",
"width": 305,
"height": 225,
"fallback": false
},
{
"ratio": "16_9",
"url": "https://s1.ticketm.net/dam/a/a01/dc895acf-863e-4f90-9316-98302e99fa01_1761311_RETINA_PORTRAIT_16_9.jpg",
"width": 640,
"height": 360,
"fallback": false
},
{
"ratio": "3_2",
"url": "https://s1.ticketm.net/dam/a/a01/dc895acf-863e-4f90-9316-98302e99fa01_1761311_TABLET_LANDSCAPE_3_2.jpg",
"width": 1024,
"height": 683,
"fallback": false
},
{
"ratio": "16_9",
"url": "https://s1.ticketm.net/dam/a/a01/dc895acf-863e-4f90-9316-98302e99fa01_1761311_RECOMENDATION_16_9.jpg",
"width": 100,
"height": 56,
"fallback": false
},
{
"ratio": "16_9",
"url": "https://s1.ticketm.net/dam/a/a01/dc895acf-863e-4f90-9316-98302e99fa01_1761311_TABLET_LANDSCAPE_LARGE_16_9.jpg",
"width": 2048,
"height": 1152,
"fallback": false
},
{
"ratio": "16_9",
"url": "https://s1.ticketm.net/dam/a/a01/dc895acf-863e-4f90-9316-98302e99fa01_1761311_RETINA_LANDSCAPE_16_9.jpg",
"width": 1136,
"height": 639,
"fallback": false
},
{
"ratio": "16_9",
"url": "https://s1.ticketm.net/dam/a/a01/dc895acf-863e-4f90-9316-98302e99fa01_1761311_TABLET_LANDSCAPE_16_9.jpg",
"width": 1024,
"height": 576,
"fallback": false
},
{
"ratio": "16_9",
"url": "https://s1.ticketm.net/dam/a/a01/dc895acf-863e-4f90-9316-98302e99fa01_1761311_EVENT_DETAIL_PAGE_16_9.jpg",
"width": 205,
"height": 115,
"fallback": false
}
],
"sales": {
"public": {
"startDateTime": "2023-08-17T19:00:00Z",
"startTBD": false,
"startTBA": false,
"endDateTime": "2023-11-20T01:00:00Z"
}
},
"dates": {
"start": {
"localDate": "2023-11-19",
"localTime": "18:00:00",
"dateTime": "2023-11-20T01:00:00Z",
"dateTBD": false,
"dateTBA": false,
"timeTBA": false,
"noSpecificTime": false
},
"status": {
"code": "onsale"
},
"spanMultipleDays": false
},
"classifications": [
{
"primary": true,
"segment": {
"id": "KZFzniwnSyZfZ7v7nE",
"name": "Sports"
},
"genre": {
"id": "KnvZfZ7vAde",
"name": "Basketball"
},
"subGenre": {
"id": "KZazBEonSMnZfZ7vFJA",
"name": "NBA"
},
"family": false
}
],
"outlets": [
{
"url": "https://www.ticketmaster.com/utah-jazz-vs-phoenix-suns-salt-lake-city-utah-11-19-2023/event/Zu0FM1R0e5tf1BT",
"type": "tmMarketPlace"
}
],
"seatmap": {
"staticUrl": "https://content.resale.ticketmaster.com/graphics/TMResale/2/VenueMaps/459-902-3-0-VivintSmartHomeArenaUtahJazz.png"
},
"ticketing": {
"allInclusivePricing": {
"enabled": false
}
},
"_links": {
"self": {
"href": "/discovery/v2/events/Z7r9jZ1AdJ9uz?locale=en-us"
},
"attractions": [
{
"href": "/discovery/v2/attractions/K8vZ9171o5V?locale=en-us"
},
{
"href": "/discovery/v2/attractions/K8vZ9171oZf?locale=en-us"
}
],
"venues": [
{
"href": "/discovery/v2/venues/Z6r9jZAk1e?locale=en-us"
}
]
},
"_embedded": {
"venues": [
{
"name": "Delta Center",
"type": "venue",
"id": "Z6r9jZAk1e",
"test": false,
"locale": "en-us",
"postalCode": "84101",
"timezone": "America/Denver",
"city": {
"name": "Salt Lake City"
},
"state": {
"name": "Utah",
"stateCode": "UT"
},
"country": {
"name": "United States Of America",
"countryCode": "US"
},
"address": {
"line1": "301 W. South Temple"
},
"location": {
"longitude": "-111.8992",
"latitude": "40.756599"
},
"dmas": [
{
"id": 378
}
],
"upcomingEvents": {
"tmr": 63,
"ticketmaster": 20,
"_total": 83,
"_filtered": 0
},
"_links": {
"self": {
"href": "/discovery/v2/venues/Z6r9jZAk1e?locale=en-us"
}
}
}
],
"attractions": [
{
"name": "Utah Jazz",
"type": "attraction",
"id": "K8vZ9171o5V",
"test": false,
"url": "https://www.ticketmaster.com/utah-jazz-tickets/artist/806035",
"locale": "en-us",
"externalLinks": {
"twitter": [
{
"url": "https://twitter.com/utahjazz"
}
],
"wiki": [
{
"url": "https://en.wikipedia.org/wiki/Utah_Jazz"
}
],
"facebook": [
{
"url": "https://www.facebook.com/utahjazz"
}
],
"instagram": [
{
"url": "https://www.instagram.com/utahjazz/"
}
],
"homepage": [
{
"url": "https://www.nba.com/jazz/"
}
]
},
"images": [
{
"ratio": "3_2",
"url": "https://s1.ticketm.net/dam/a/a01/dc895acf-863e-4f90-9316-98302e99fa01_1761311_RETINA_PORTRAIT_3_2.jpg",
"width": 640,
"height": 427,
"fallback": false
},
{
"ratio": "3_2",
"url": "https://s1.ticketm.net/dam/a/a01/dc895acf-863e-4f90-9316-98302e99fa01_1761311_ARTIST_PAGE_3_2.jpg",
"width": 305,
"height": 203,
"fallback": false
},
{
"ratio": "4_3",
"url": "https://s1.ticketm.net/dam/a/a01/dc895acf-863e-4f90-9316-98302e99fa01_1761311_CUSTOM.jpg",
"width": 305,
"height": 225,
"fallback": false
},
{
"ratio": "16_9",
"url": "https://s1.ticketm.net/dam/a/a01/dc895acf-863e-4f90-9316-98302e99fa01_1761311_RETINA_PORTRAIT_16_9.jpg",
"width": 640,
"height": 360,
"fallback": false
},
{
"ratio": "3_2",
"url": "https://s1.ticketm.net/dam/a/a01/dc895acf-863e-4f90-9316-98302e99fa01_1761311_TABLET_LANDSCAPE_3_2.jpg",
"width": 1024,
"height": 683,
"fallback": false
},
{
"ratio": "16_9",
"url": "https://s1.ticketm.net/dam/a/a01/dc895acf-863e-4f90-9316-98302e99fa01_1761311_RECOMENDATION_16_9.jpg",
"width": 100,
"height": 56,
"fallback": false
},
{
"ratio": "16_9",
"url": "https://s1.ticketm.net/dam/a/a01/dc895acf-863e-4f90-9316-98302e99fa01_1761311_TABLET_LANDSCAPE_LARGE_16_9.jpg",
"width": 2048,
"height": 1152,
"fallback": false
},
{
"ratio": "16_9",
"url": "https://s1.ticketm.net/dam/a/a01/dc895acf-863e-4f90-9316-98302e99fa01_1761311_RETINA_LANDSCAPE_16_9.jpg",
"width": 1136,
"height": 639,
"fallback": false
},
{
"ratio": "16_9",
"url": "https://s1.ticketm.net/dam/a/a01/dc895acf-863e-4f90-9316-98302e99fa01_1761311_TABLET_LANDSCAPE_16_9.jpg",
"width": 1024,
"height": 576,
"fallback": false
},
{
"ratio": "16_9",
"url": "https://s1.ticketm.net/dam/a/a01/dc895acf-863e-4f90-9316-98302e99fa01_1761311_EVENT_DETAIL_PAGE_16_9.jpg",
"width": 205,
"height": 115,
"fallback": false
}
],
"classifications": [
{
"primary": true,
"segment": {
"id": "KZFzniwnSyZfZ7v7nE",
"name": "Sports"
},
"genre": {
"id": "KnvZfZ7vAde",
"name": "Basketball"
},
"subGenre": {
"id": "KZazBEonSMnZfZ7vFJA",
"name": "NBA"
},
"type": {
"id": "KZAyXgnZfZ7v7l1",
"name": "Group"
},
"subType": {
"id": "KZFzBErXgnZfZ7vA7d",
"name": "Team"
},
"family": false
}
],
"upcomingEvents": {
"tmr": 42,
"ticketmaster": 26,
"_total": 68,
"_filtered": 0
},
"_links": {
"self": {
"href": "/discovery/v2/attractions/K8vZ9171o5V?locale=en-us"
}
}
},
{
"name": "Phoenix Suns",
"type": "attraction",
"id": "K8vZ9171oZf",
"test": false,
"url": "https://www.ticketmaster.com/phoenix-suns-tickets/artist/806004",
"locale": "en-us",
"externalLinks": {
"twitter": [
{
"url": "https://twitter.com/Suns"
}
],
"wiki": [
{
"url": "https://en.wikipedia.org/wiki/Phoenix_Suns"
}
],
"facebook": [
{
"url": "https://www.facebook.com/suns/"
}
],
"instagram": [
{
"url": "https://www.instagram.com/suns/"
}
],
"homepage": [
{
"url": "https://www.nba.com/suns/"
}
]
},
"aliases": [
"phoenix",
"suns",
"phoenix suns exchange",
"phoenix suns team exchange",
"phoenix suns season ticket holders",
"phoenix suns season tix holders",
"phoenix suns ticket exchange",
"suns exchange",
"suns season ticket holders",
"suns season tix holders",
"suns team exchange",
"suns ticket exchange"
],
"images": [
{
"ratio": "4_3",
"url": "https://s1.ticketm.net/dam/a/c62/0636ff21-e369-4b8c-bee4-214ea0a81c62_1339761_CUSTOM.jpg",
"width": 305,
"height": 225,
"fallback": false
},
{
"ratio": "16_9",
"url": "https://s1.ticketm.net/dam/a/c62/0636ff21-e369-4b8c-bee4-214ea0a81c62_1339761_RETINA_PORTRAIT_16_9.jpg",
"width": 640,
"height": 360,
"fallback": false
},
{
"ratio": "16_9",
"url": "https://s1.ticketm.net/dam/a/c62/0636ff21-e369-4b8c-bee4-214ea0a81c62_1339761_TABLET_LANDSCAPE_LARGE_16_9.jpg",
"width": 2048,
"height": 1152,
"fallback": false
},
{
"ratio": "16_9",
"url": "https://s1.ticketm.net/dam/a/c62/0636ff21-e369-4b8c-bee4-214ea0a81c62_1339761_EVENT_DETAIL_PAGE_16_9.jpg",
"width": 205,
"height": 115,
"fallback": false
},
{
"ratio": "3_2",
"url": "https://s1.ticketm.net/dam/a/c62/0636ff21-e369-4b8c-bee4-214ea0a81c62_1339761_ARTIST_PAGE_3_2.jpg",
"width": 305,
"height": 203,
"fallback": false
},
{
"ratio": "16_9",
"url": "https://s1.ticketm.net/dam/a/c62/0636ff21-e369-4b8c-bee4-214ea0a81c62_1339761_TABLET_LANDSCAPE_16_9.jpg",
"width": 1024,
"height": 576,
"fallback": false
},
{
"ratio": "3_2",
"url": "https://s1.ticketm.net/dam/a/c62/0636ff21-e369-4b8c-bee4-214ea0a81c62_1339761_RETINA_PORTRAIT_3_2.jpg",
"width": 640,
"height": 427,
"fallback": false
},
{
"ratio": "3_2",
"url": "https://s1.ticketm.net/dam/a/c62/0636ff21-e369-4b8c-bee4-214ea0a81c62_1339761_TABLET_LANDSCAPE_3_2.jpg",
"width": 1024,
"height": 683,
"fallback": false
},
{
"ratio": "16_9",
"url": "https://s1.ticketm.net/dam/a/c62/0636ff21-e369-4b8c-bee4-214ea0a81c62_1339761_RETINA_LANDSCAPE_16_9.jpg",
"width": 1136,
"height": 639,
"fallback": false
},
{
"ratio": "16_9",
"url": "https://s1.ticketm.net/dam/a/c62/0636ff21-e369-4b8c-bee4-214ea0a81c62_1339761_RECOMENDATION_16_9.jpg",
"width": 100,
"height": 56,
"fallback": false
}
],
"classifications": [
{
"primary": true,
"segment": {
"id": "KZFzniwnSyZfZ7v7nE",
"name": "Sports"
},
"genre": {
"id": "KnvZfZ7vAde",
"name": "Basketball"
},
"subGenre": {
"id": "KZazBEonSMnZfZ7vFJA",
"name": "NBA"
},
"type": {
"id": "KZAyXgnZfZ7v7l1",
"name": "Group"
},
"subType": {
"id": "KZFzBErXgnZfZ7vA7d",
"name": "Team"
},
"family": false
}
],
"upcomingEvents": {
"tmr": 9,
"ticketmaster": 60,
"_total": 69,
"_filtered": 0
},
"_links": {
"self": {
"href": "/discovery/v2/attractions/K8vZ9171oZf?locale=en-us"
}
}
}
]
}
}
]
型
误差
[
{
"date_time": [
"This field is required."
],
"icon": [
"This field is required."
],
"event": [
"This field is required."
],
"genre": [
"This field is required."
],
"venue": [
"This field is required."
]
}
]
型
1条答案
按热度按时间7gyucuyw1#
我得到了这个问题基本上我采取了错误的方式的关键字源的含义源关键字描述的输出字段,而不是传递对象的属性