我知道这个问题有几个高质量的答案,但我正在努力使用语法来让它工作:
$.getJSON( "ticketweb.json",
function(data){
$.each(data.events, function(){
$('ul#listings').append("<li><div class=event-col><span class=name>" +this.eventname+ "</span><p>" +this.eventurl+ "</p><div class=date>" +this.dates.startdate+ "</div><p>" +this.eventimages+ "</p><p>" +this.venue.name+ "</p></div></li>");
});
});
在哪里
<div class=date>" +this.dates.startdate+ "</div>
.append 的一部分是我想要格式化的位。我尝试了很多方法,但不确定如何将更通用的 json 格式方法合并到上述语法中。
编辑:我理想的日期格式是:11 月 17 日星期六,尽管 17.11.12 也可以。
我当前得到的输出是 20120629100000。没有像我在类似问题上看到的那样的正斜杠或反斜杠 (/Date(1224043200000)/),我不确定这里是否缺少良好的编码实践元素. 我的 JSON 文件在下面输入是完全有效的:
"events": [
{
"eventid": "4419605",
"facebookeventid": "",
"eventname": "",
"description": "",
"eventurl": "",
"additionallistingtext": "",
"status": "SalesEnded",
"tags": "",
"spotifyuri": "",
"dates": {
"startdate": "20120529010000",
"enddate": "20121231235500",
"onsaledate": "20120309084000",
"announcedate": "20120309115333",
"timezone": "EDT"
},
"venue": {
"venueid": "210795",
"name": "Online",
"venueurl": "",
"city": "Online",
"state": "",
"postalcode": "00000",
"country": "US",
"address": "Online",
"twitterid": "",
"venueimages": {
"large": "",
"small": ""
}
},
"eventimages": [""],
"prices": {
"pricelow": "$195.00",
"pricehigh": "$195.00",
"pricedisplay": "$195.00"
},
"attractionList": [
{
"sequence": "0",
"billing": "1.00",
"genre": "Seminar/Lecture",
"links": "",
"media": ""
},
{
"sequence": "1",
"billing": "0.75",
"links": "",
"media": ""
},
{
"sequence": "2",
"billing": "0.75",
"links": "",
"media": ""
}
]
},