aspJSON 错误 - 加载 JSON 引发溢出“Clng”+ 无法迭代多条记录

问题描述

我正在尝试遍历一些基本的 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,""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"",""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""},""keywords"":""base sas,sas,online training,virtualnuggets"",""prices"":{""Training"":""USD 0""},""workflow_state"":""reported_on"",""venue"":{""id"":26319,""name"":""station road"",""address_1"":""station road"",""town"":""Sandwell"",""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,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,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,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,"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","summary": "VirtualNuggets is the one of Best organization providing Online and Corporate Training worldwide.","description": "Base SAS provides a scalable,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"
    },"keywords": "base sas,virtualnuggets","prices": {
        "Training": "USD 0"
    },"workflow_state": "reported_on","venue": {
        "id": 26319,"name": "station road","address_1": "station road","town": "Sandwell","postcode": "B71 4HJ","latitude": 52.5273431,"longitude": -1.9883300652359
    },"contact": {
        "name": "Contact Name 43585","email": "contact43585@example.com","tel": "123456789"
    }
}]

*** 更新 ***

JSON 代码在它周围丢失了 [ ],它现在将通过第一次迭代并在第二次遇到 Object required: 'oJSON.data(...).Item(...)' 时出现 Set this = oJSON.data("events").item(oEvent) 错误。我清理了上面的代码,这是我打印的第一次迭代:

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(...)'

解决方法

这是这个问题的答案。问题与 JSON 和缺少括号有关 - 哎呀!希望这对某人有所帮助。

  1. Flakes 在评论中的建议解决了 CLNG 问题 - 谢谢。

  2. 循环示例 - 这里是完整代码。

    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,""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"",""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""},""keywords"":""base sas,sas,online training,virtualnuggets"",""prices"":{""Training"":""USD 0""},""workflow_state"":""reported_on"",""venue"":{""id"":26319,""name"":""station road"",""address_1"":""station road"",""town"":""Sandwell"",""postcode"":""B71 4HJ"",""latitude"":52.5273431,""longitude"":-1.9883300652359},""contact"":{""name"":""Contact Name 43585"",""email"":""contact43585@example.com"",""tel"":""123456789""}}"

    'Wrap with "events" to turn it into a collection
    strJSON = "{""events"":[" & strJSON & "]}"

    Set oJSON = New aspJSON

    'Load JSON string
    oJSON.loadJSON(strJSON)

    'Loop through each record in the collection
    i = 0
    For Each eventrec In oJSON.data("events")
        
        'Shorthand access to each record
        Set this = oJSON.data("events").item(eventrec)

        'Access the base level items
        Response.Write i & ") " & this.item("id") & " = " & this.item("title") & "<br>"
        
        'Get Images
        bStop = False
        c = 0
        Do Until bStop
            If Len(this.item("image_urls").item(c)) > 0 Then
                Response.Write this.item("image_urls").item(c) & "<br>"
            Else
                bStop = True
            End If
            c = c + 1
        Loop
                
        'Links
        For Each link In this.item("links")
            Response.Write link & ":" & this.item("links").item(link) & "<br>"
        Next

        'Venue
        For Each link In this.item("venue")
            Response.Write link & ":" & this.item("venue").item(link) & "<br>"
        Next

        i = i + 1
    Next