【发布时间】:2021-06-02 20:01:24
【问题描述】:
我正在尝试遍历一些基本的 JSON,但由于某种原因,我在加载 JSON 时遇到了一个溢出:“Clng”错误并且无法弄清楚原因。任何帮助将不胜感激,谢谢。
我正在使用此处的 EXACT 1.19 版代码:https://github.com/gerritvankuipers/aspjson/blob/master/aspJSON1.19.asp(脚本第 265 行发生错误)
这是 JSON:(它是有效的 JSON - 我在 https://jsonlint.com/ 上测试过)
strJSON = "[{""id"":29599,""title"":""Lucky Voice"",""category_id"":45,""sub_category_ids"":[],""timestamp"":""2015-07-01T13:06:31.851013Z"",""start_time"":""2015-07-01T17:00:00+01:00"",""end_time"":""2021-07-01T03:00:00+01:00"",""door_time"":null,""last_entry_time"":null,""summary"":""Lucky Voice is the most liberating, heart-racing, life-affirming private karaoke experience on Earth. But don't just take our word for it..."",""description"":""Lucky Voice - simply the best! Hire out one of our karaoke rooms for you and your friends and experience some of the best fun around. Whether you are 12 or 92 and love singing, then this is the place for you! Plus, you wont be disturbed by anyone, unless of course, you press the \""thirsty\"" button for a drink...\r\n\r\nOpening Hours:\r\nMon - Wed 5:30pm - 1:00am\r\nThurs - Sat 5:30pm - 3:00am\r\nSun 3:00pm - 10:30pm"",""organiser_name"":""Lucky Voice"",""hashtag"":""luckyvoice"",""image_url"":""https://s3-eu-west-1.amazonaws.com/evvnt.staging/uploads/event_image/event_image/4626090b-9c8d-484d-92e6-c0331d4af9cd/soho3.jpg"",""image_urls"":[""https://s3-eu-west-1.amazonaws.com/evvnt.staging/uploads/event_image/event_image/4626090b-9c8d-484d-92e6-c0331d4af9cd/soho3.jpg"",""https://s3-eu-west-1.amazonaws.com/evvnt.staging/uploads/event_image/event_image/7199c9d4-cfe2-44e9-9523-a1d9e9a78e0d/Brighton%20Pod2.jpg""],""links"":{""Website"":""http://go-staging.evvnt.com/29599-0"",""Booking"":""http://go-staging.evvnt.com/29599-1"",""Facebook"":""http://go-staging.evvnt.com/29599-2"",""Twitter"":""http://go-staging.evvnt.com/29599-3"",""YouTube"":""http://go-staging.evvnt.com/29599-4""},""artists"":"""",""keywords"":""karaoke, lucky voice, soho"",""prices"":{""Average pp"":""GBP 22""},""workflow_state"":""report_complete"",""capacity"":null,""venue"":{""id"":16838,""name"":""Lucky Voice"",""address_1"":""52 Poland Street"",""address_2"":"""",""town"":""London"",""country"":""GB"",""postcode"":""W1F 7NQ"",""latitude"":51.5146901,""longitude"":-0.136974},""contact"":{""name"":""Contact Name 26421"",""email"":""contact26421@example.com"",""tel"":""123456789""}},{""id"":46658,""title"":""Base SAS Online Training at VirtualNuggets.com"",""category_id"":124,""sub_category_ids"":[],""timestamp"":""2016-02-10T05:19:39.666806Z"",""start_time"":""2016-02-12T01:00:00+00:00"",""end_time"":""2024-08-17T23:00:00+01:00"",""door_time"":null,""last_entry_time"":null,""summary"":""VirtualNuggets is the one of Best organization providing Online and Corporate Training worldwide."",""description"":""Base SAS provides a scalable, included software environment specially designed for data access, alteration and reporting. It includes a fourth-generation programming language; ready-to-use programs for data handling, information storage and recovery, evocative statistics and report writing; and an influential macro facility that reduces programming time and preservation headaches.\r\n\r\nVirtualNuggets is the one of Best organization providing Online and Corporate Training worldwide. We offer Real-time practical Oriented Training on Base SAS, New batch starts on every week.\r\n\r\nFor more information on Base SAS Online Training\r\n\r\nEmail\t : info@virtualnuggets com\r\nContact : +1-707 666 8949(USA)\t +91-888 556 0202(India)\r\nWeb URL : http://www.virtualnuggets.com/base-sas.html\r\nBlogger : http://basesasonlinetraining.blogspot.com\r\n"",""organiser_name"":""vasubuddi"",""hashtag"":""basesas"",""image_url"":""https://s3-eu-west-1.amazonaws.com/evvnt.staging/uploads/event_image/event_image/a49c513e-f8ce-4095-b51d-989e7d8e3d75/VirtualNuggets.png"",""image_urls"":[""https://s3-eu-west-1.amazonaws.com/evvnt.staging/uploads/event_image/event_image/a49c513e-f8ce-4095-b51d-989e7d8e3d75/VirtualNuggets.png""],""links"":{""Website"":""http://go-staging.evvnt.com/46658-0"",""Inquiries"":""http://go-staging.evvnt.com/46658-1""},""artists"":"""",""keywords"":""base sas, sas, online training, virtualnuggets"",""prices"":{""Training"":""USD 0""},""workflow_state"":""reported_on"",""capacity"":null,""venue"":{""id"":26319,""name"":""station road"",""address_1"":""station road"",""address_2"":"""",""town"":""Sandwell"",""country"":""GB"",""postcode"":""B71 4HJ"",""latitude"":52.5273431,""longitude"":-1.9883300652359},""contact"":{""name"":""Contact Name 43585"",""email"":""contact43585@example.com"",""tel"":""123456789""}}]"
这是处理代码:
Set oJSON = New aspJSON
'Wrap with events to turn it into a collection so we can loop below (i commented this out, i get the same error regardless though).
'From here: https://stackoverflow.com/questions/30782144/looping-through-json-using-aspjson
strJSON = "{""events"":" & strJSON & "}"
'Load JSON string
oJSON.loadJSON(strJSON)
一旦我们加载了 JSON,我就无法打印出每条记录中的数据 - 我得到了:
'Loop through each item in collection
For Each oEvent In oJSON.data("events")
'Errors Here: Object required: '[string: "29599"]'
Set this = oJSON.data("events").item(oEvent)
Response.Write this.item("id") & ": " & this.item("title") & "<br>"
For Each link In this.item("links")
Response.Write link & ":" & this.item("links").item(link) & "<br>"
Next
Next
我需要做的是打印/访问每个 ID(29599 和 46658)以及它下面的所有数据。这里有两条记录,但可能返回 1000 条。
这是格式化的有效 JSON 字符串:
[{
"id": 29599,
"title": "Lucky Voice",
"category_id": 45,
"sub_category_ids": [],
"timestamp": "2015-07-01T13:06:31.851013Z",
"start_time": "2015-07-01T17:00:00+01:00",
"end_time": "2021-07-01T03:00:00+01:00",
"door_time": null,
"last_entry_time": null,
"summary": "Lucky Voice is the most liberating, heart-racing, life-affirming private karaoke experience on Earth. But don't just take our word for it...",
"description": "Lucky Voice - simply the best! Hire out one of our karaoke rooms for you and your friends and experience some of the best fun around. Whether you are 12 or 92 and love singing, then this is the place for you! Plus, you wont be disturbed by anyone, unless of course, you press the \"thirsty\" button for a drink...\r\n\r\nOpening Hours:\r\nMon - Wed 5:30pm - 1:00am\r\nThurs - Sat 5:30pm - 3:00am\r\nSun 3:00pm - 10:30pm",
"organiser_name": "Lucky Voice",
"hashtag": "luckyvoice",
"image_url": "https://s3-eu-west-1.amazonaws.com/evvnt.staging/uploads/event_image/event_image/4626090b-9c8d-484d-92e6-c0331d4af9cd/soho3.jpg",
"image_urls": ["https://s3-eu-west-1.amazonaws.com/evvnt.staging/uploads/event_image/event_image/4626090b-9c8d-484d-92e6-c0331d4af9cd/soho3.jpg", "https://s3-eu-west-1.amazonaws.com/evvnt.staging/uploads/event_image/event_image/7199c9d4-cfe2-44e9-9523-a1d9e9a78e0d/Brighton%20Pod2.jpg"],
"links": {
"Website": "http://go-staging.evvnt.com/29599-0",
"Booking": "http://go-staging.evvnt.com/29599-1",
"Facebook": "http://go-staging.evvnt.com/29599-2",
"Twitter": "http://go-staging.evvnt.com/29599-3",
"YouTube": "http://go-staging.evvnt.com/29599-4"
},
"artists": "",
"keywords": "karaoke, lucky voice, soho",
"prices": {
"Average pp": "GBP 22"
},
"workflow_state": "report_complete",
"capacity": null,
"venue": {
"id": 16838,
"name": "Lucky Voice",
"address_1": "52 Poland Street",
"address_2": "",
"town": "London",
"country": "GB",
"postcode": "W1F 7NQ",
"latitude": 51.5146901,
"longitude": -0.136974
},
"contact": {
"name": "Contact Name 26421",
"email": "contact26421@example.com",
"tel": "123456789"
}
}, {
"id": 46658,
"title": "Base SAS Online Training at VirtualNuggets.com",
"category_id": 124,
"sub_category_ids": [],
"timestamp": "2016-02-10T05:19:39.666806Z",
"start_time": "2016-02-12T01:00:00+00:00",
"end_time": "2024-08-17T23:00:00+01:00",
"door_time": null,
"last_entry_time": null,
"summary": "VirtualNuggets is the one of Best organization providing Online and Corporate Training worldwide.",
"description": "Base SAS provides a scalable, included software environment specially designed for data access, alteration and reporting. It includes a fourth-generation programming language; ready-to-use programs for data handling, information storage and recovery, evocative statistics and report writing; and an influential macro facility that reduces programming time and preservation headaches.\r\n\r\nVirtualNuggets is the one of Best organization providing Online and Corporate Training worldwide. We offer Real-time practical Oriented Training on Base SAS, New batch starts on every week.\r\n\r\nFor more information on Base SAS Online Training\r\n\r\nEmail\t : info@virtualnuggets com\r\nContact : +1-707 666 8949(USA)\t +91-888 556 0202(India)\r\nWeb URL : http://www.virtualnuggets.com/base-sas.html\r\nBlogger : http://basesasonlinetraining.blogspot.com\r\n",
"organiser_name": "vasubuddi",
"hashtag": "basesas",
"image_url": "https://s3-eu-west-1.amazonaws.com/evvnt.staging/uploads/event_image/event_image/a49c513e-f8ce-4095-b51d-989e7d8e3d75/VirtualNuggets.png",
"image_urls": ["https://s3-eu-west-1.amazonaws.com/evvnt.staging/uploads/event_image/event_image/a49c513e-f8ce-4095-b51d-989e7d8e3d75/VirtualNuggets.png"],
"links": {
"Website": "http://go-staging.evvnt.com/46658-0",
"Inquiries": "http://go-staging.evvnt.com/46658-1"
},
"artists": "",
"keywords": "base sas, sas, online training, virtualnuggets",
"prices": {
"Training": "USD 0"
},
"workflow_state": "reported_on",
"capacity": null,
"venue": {
"id": 26319,
"name": "station road",
"address_1": "station road",
"address_2": "",
"town": "Sandwell",
"country": "GB",
"postcode": "B71 4HJ",
"latitude": 52.5273431,
"longitude": -1.9883300652359
},
"contact": {
"name": "Contact Name 43585",
"email": "contact43585@example.com",
"tel": "123456789"
}
}]
*** 更新 ***
JSON 代码在它周围缺少 [ ],它现在将通过第一次迭代,并在第二次到达 Set this = oJSON.data("events").item(oEvent) 时出现 Object required: 'oJSON.data(...).Item(...)' 错误。我清理了上面的代码,这是我打印的第一次迭代:
29599: Lucky Voice
Website:http://go-staging.evvnt.com/29599-0
Booking:http://go-staging.evvnt.com/29599-1
Facebook:http://go-staging.evvnt.com/29599-2
Twitter:http://go-staging.evvnt.com/29599-3
YouTube:http://go-staging.evvnt.com/29599-4
ERROR: Object required: 'oJSON.data(...).Item(...)'
【问题讨论】:
-
VBScript 字符串中有很多 JSON,您能否编辑问题并添加 RAW JSON(不是 VBScript 字符串)以便我们查看。目前的形式很难阅读。
-
在底部添加。你可以在这里验证它:jsonlint.com
-
当您的json中的数字在小数点后有太多数字时,错误是由于溢出,(例如:“经度”:-1.9883300652359)。在链接的 aspjson 文件中的
aj_ReadNumericValue函数中,代码尝试将此值强制转换为 long 删除小数点,从而导致溢出。在链接的aspjson文件中找到val = Clng(Replace(val, ".", "")),改成val = CDbl(Replace(val, ".", ""))。 -
这似乎奏效了。我遇到的新问题 - 如何使用 aspJSON 遍历多个级别?他们的网站上没有这样的例子:github.com/gerritvankuipers/aspjson(它们是单级的)您将在上面的格式化 JSON 中看到有两条记录 - id 29599 和 id 46658。我花了一个多小时,没有例子(我也可以在谷歌上找到),这很奇怪!感谢您的帮助。
-
完全同意 - 有多少人使用这个?!
标签: json asp-classic