如何将循环中的值添加到asp经典中的数组?

问题描述

在循环中,我向页面发送请求,在 200 状态回调中,我需要创建一个数组,其中包含在回调中返回的响应。

photoarray=array(photoarray)

    For Each x In imagearray
       --sending request to a page here----
       If objXmlHttp.Status = 200 Then

            photoId=oJSON.data("id")
            --I need to add all the photoIds that I get here into the photoarray--
                
       end if
    Next

response.write "All ids in this array "&photoarray

那么如何向 photoarray 推送或添加值?

最后,我需要使用循环中获得的 photoId 创建一个这样的字符串。

media_id="{media_id:12345,media_id:45678,media_id:98765}"

非常感谢。

解决方法

为了保留您现有的代码,我可能建议将所有响应 ID 附加到由唯一字符分隔的单个字符串中(例如,counter),然后使用 | 函数轻松转换字符串循环后放入数组。

例如:

Split()