将 Json 字符串解析为经典 ASP 页面
Parse Json string to Classic ASP page
使用库将 json 字符串解析为经典 asp 的最佳方法是什么?
Dim jsonString
jsonString = {"date":"4/28/2017","custType":"100","vehicle":"1"}
想拥有
response.write("<li> date :" & json("date") & "</li>")
成功了:
使用https://github.com/rcdmk/aspJSON
Dim jsonString
jsonString = {"date":"4/28/2017","custType":"100","vehicle":"1"}
Dim jsonObj, outputObj
set jsonObj = new JSONobject
set outputObj = jsonObj.parse(jsonString)
response.write("<li> date :" & outputObj("date") & "</li>")
response.write("<li> custType :" & outputObj("custType") & "</li>")
response.write("<li> vehicle :" & outputObj("vehicle") & "</li>")
如果您需要遍历单个对象,请使用 outputObj.pairs
Dim props, prop
props = outputObj.pairs
for each prop in props
response.write prop.name & " : " & prop.value & "<br>"
next
作为简单 json 结构和转义值的快速解决方案,这个简单的函数 returns 通过在双引号 chr(34)
上拆分 json 字符串来获取键值:
function getKeyValue(JsonString,key)
myarray=split(JsonString,key,-1,1)
if ubound(myarray)>0 then
myarray2=split(myarray(1),chr(34),-1,1)
getKeyValue=myarray2(2)
else
getKeyValue=""
end if
end function
用法:
response.write("<li> date :" & getKeyValue(Your_Json_String_Here,"date") & "</li>")
使用库将 json 字符串解析为经典 asp 的最佳方法是什么?
Dim jsonString
jsonString = {"date":"4/28/2017","custType":"100","vehicle":"1"}
想拥有
response.write("<li> date :" & json("date") & "</li>")
成功了:
使用https://github.com/rcdmk/aspJSON
Dim jsonString
jsonString = {"date":"4/28/2017","custType":"100","vehicle":"1"}
Dim jsonObj, outputObj
set jsonObj = new JSONobject
set outputObj = jsonObj.parse(jsonString)
response.write("<li> date :" & outputObj("date") & "</li>")
response.write("<li> custType :" & outputObj("custType") & "</li>")
response.write("<li> vehicle :" & outputObj("vehicle") & "</li>")
如果您需要遍历单个对象,请使用 outputObj.pairs
Dim props, prop
props = outputObj.pairs
for each prop in props
response.write prop.name & " : " & prop.value & "<br>"
next
作为简单 json 结构和转义值的快速解决方案,这个简单的函数 returns 通过在双引号 chr(34)
上拆分 json 字符串来获取键值:
function getKeyValue(JsonString,key)
myarray=split(JsonString,key,-1,1)
if ubound(myarray)>0 then
myarray2=split(myarray(1),chr(34),-1,1)
getKeyValue=myarray2(2)
else
getKeyValue=""
end if
end function
用法:
response.write("<li> date :" & getKeyValue(Your_Json_String_Here,"date") & "</li>")