在经典asp.NET中解析json字符串
我这里有一根这样的线:在经典asp.NET中解析json字符串,asp.net,json,regex,Asp.net,Json,Regex,我这里有一根这样的线: { "status":"SUCCESS", "response":{ "offset":0, "max":50, "count":1, "locations":[ { "identifier":"0022", "id":322433, "dateCreated":"2015-
{
"status":"SUCCESS",
"response":{
"offset":0,
"max":50,
"count":1,
"locations":[
{
"identifier":"0022",
"id":322433,
"dateCreated":"2015-10-29T11:26:29.000+01:00",
"lastUpdated":"2017-02-13T06:22:35.000+01:00",
"name":"Something something",
"street":"Some street",
"streetNo":"3",
"streetAndNumber":"some text 3",
"addressExtra":null,
"zip":"12345",
"city":"foobar",
"cellphone":null,
"fax": null",
"website":null,
"email":null,
"descriptionShort":"desc",
"descriptionLong":"desc2",
"openingHoursNotes":"desc3",
"lastSyncStarted":"2016-09-12T11:14:24.000+02:00",
"country":"DE",
"lat":49.000,
"lng":8.0000,
"imprint":null,
"addressDisplay":null,
"autoSync":null,
"phone":"null,
"status":"ACTIVE",
"keywords":[
"some keywords"
],
"categories":[
534
],
"locationSyncable":false,
"businessId":11111,
"socialPostId":null,
"hasFacebook":false,
"endDate":"2017-02-28T00:00:00.000+01:00",
"openingHours":[
{
"dayOfWeek":1,
"from1":"07:00",
"to1":"17:00"
},
{
"dayOfWeek":2,
"from1":"07:00",
"to1":"17:00"
},
{
"dayOfWeek":3,
"from1":"07:00",
"to1":"17:00"
},
{
"dayOfWeek":4,
"from1":"07:00",
"to1":"17:00"
},
{
"dayOfWeek":5,
"from1":"07:00",
"to1":"17:00"
},
{
"dayOfWeek":6,
"from1":"07:30",
"to1":"12:00"
}
],
"openNow":true,
"activeDirectoriesCount":45,
"activeListingsCount":33,
"publishedListingsCount":45,
"profileCompleteness":100,
"missingMandatoryFields":[
],
"visibilityIndex":559,
"dataPoints":0,
"province":"Germany"
}
]
}
}
我必须检索id
第一次出现的值-在上面的情况下,它应该返回322433
我为什么这样说?因为我考虑过使用substr
(或类似的东西)或regexp
来获得我需要的值,并且查找id:“
以多次出现结束-而且它不会干净,只是一个混乱的解决方法
所以,我知道有几个相关的问题,我已经讨论过了所有这些问题,但我对经典的asp完全是新手。来自PHP,内置JSON解析器,我被宠坏了,我有点迷路了
我在git上发现了一个类,它应该可以处理这个问题,但我无法让它运行
看到这一点。我尝试了完全相同的方法。保存了文件,像其他文件一样包含它,并尝试创建一个新类,但最终出现了未定义类
错误
也许这已经结束了?我真的只需要这一次。没有动态生成的输出。这总是来自curl
-请求的响应,我只需要得到这个特定的id
。性能扮演着一个相关的角色,我想,使用整个类来达到这个目的会有些过头
我也尝试了这个VScript
,但正如上面提到的,我在这里有点迷路了
为了提供我的所有代码,我将向您展示我现在遇到的问题:
函数determineLocationId(标识符)
Dim http:Set http=Server.CreateObject(“WinHttp.WinHttpRequest.5.1”)
暗私钥
privateKey=“非常机密”
IdentifyUrl=“someUrl”
使用http
Call.Open(“GET”,IdentifyUrl,false)
SetRequestHeader(“内容类型”,“应用程序/json;字符集=UTF-8”)
Call.SetRequestHeader(“字符集”、“utf-8”)
Call.Send()
以
如果左(http.Status,1)=2,则
回复。填写(“更新”)
其他的
'输出错误
Call Response.Write(“服务器返回:”&http.Status&“&http.StatusText”)
如果结束
write(http.responseText)'这将从上面输出json
答复:end()
determiniteLocationID=标识符
端函数
您可以尝试以下方法:
Dim str, parser, match, id
str = http.responseText
Set parser = New Regexp
With parser
.Pattern = """id"":(\d+)"
.Global = False
End With
Set match = parser.Execute(str)
id = match(0).SubMatches(0)
response.write(id)