第一種方法
<%
Dim jsonStr, json
jsonStr = GetFile("json.txt")
Set json = parseJSON(jsonStr)
Response.Write "status: " & json.status & "<br />"
Response.Write "city_name: " & json.weather.get(0).city_name & "<br />" & VbCrLf
Dim future, C, I
Set future = json.weather.get(0).future
C = future.length - 1
Response.Write "<table border='1' cellspacing='0'>"
Response.Write "<tr><td>date</td><td>high</td><td>low</td><td>day</td><td>text</td><td>code1</td><td>code2</td><td>cop</td><td>wind</td></tr>"
For I = 0 To C
Response.Write "<tr><td>" & future.Get(I).date & "</td>" & VbCrLf & _
"<td>" & future.Get(I).high & "</td>" & VbCrLf & _
"<td>" & future.Get(I).low & "</td>" & VbCrLf & _
"<td>" & future.Get(I).day & "</td>" & VbCrLf & _
"<td>" & future.Get(I).text & "</td>" & VbCrLf & _
"<td>" & future.Get(I).code1 & "</td>" & VbCrLf & _
"<td>" & future.Get(I).code2 & "</td>" & VbCrLf & _
"<td>" & future.Get(I).cop & "</td>" & VbCrLf & _
"<td>" & future.Get(I).wind & "</td>" & VbCrLf & _
"</tr>"
Next
Response.Write "</table>"
'PR getjson(jsonStr)
Dim scriptCtrl
Function parseJSON(str)
If Not IsObject(scriptCtrl) Then
Set scriptCtrl = Server.CreateObject("MSScriptControl.ScriptControl")
scriptCtrl.Language = "JScript"
scriptCtrl.AddCode "Array.prototype.get = function(x) { return this[x]; }; var result = null;"
End If
scriptCtrl.ExecuteStatement "result = " & str & ";"
Set parseJSON = scriptCtrl.CodeObject.result
End Function
Function GetFile(sFileName)
Dim oFso, oFout
Set oFso = Server.CreateObject("Scripting.FileSystemObject")
If oFso.FileExists(Server.Mappath(sFileName)) Then
Set oFout = oFso.OpenTextFile(Server.Mappath(sFileName), 1, False)
On Error Resume Next
GetFile = oFout.ReadAll()
If Err Then
Err.Clear
GetFile = ""
End If
oFout.Close
Set oFout = Nothing
Else
GetFile = ""
End If
Set oFso = Nothing
End Function
%>
第二種方法
<%
Dim jsonStr, json
jsonStr = GetFile("json.txt")
Set json = parseJSON(jsonStr)
Response.Write "status: " & json.status & "<br />"
Response.Write "city_name: " & json.weather.get(0).city_name & "<br />" & VbCrLf
Dim future, C, I
Set future = json.weather.get(0).future
C = future.length - 1
Response.Write "<table border='1' cellspacing='0'>"
Response.Write "<tr><td>date</td><td>high</td><td>low</td><td>day</td><td>text</td><td>code1</td><td>code2</td><td>cop</td><td>wind</td></tr>"
For I = 0 To C
Response.Write "<tr><td>" & future.Get(I).date & "</td>" & VbCrLf & _
"<td>" & future.Get(I).high & "</td>" & VbCrLf & _
"<td>" & future.Get(I).low & "</td>" & VbCrLf & _
"<td>" & future.Get(I).day & "</td>" & VbCrLf & _
"<td>" & future.Get(I).text & "</td>" & VbCrLf & _
"<td>" & future.Get(I).code1 & "</td>" & VbCrLf & _
"<td>" & future.Get(I).code2 & "</td>" & VbCrLf & _
"<td>" & future.Get(I).cop & "</td>" & VbCrLf & _
"<td>" & future.Get(I).wind & "</td>" & VbCrLf & _
"</tr>"
Next
Response.Write "</table>"
'PR getjson(jsonStr)
Dim scriptCtrl
Function parseJSON(str)
If Not IsObject(scriptCtrl) Then
Set scriptCtrl = Server.CreateObject("MSScriptControl.ScriptControl")
scriptCtrl.Language = "JScript"
scriptCtrl.AddCode "Array.prototype.get = function(x) { return this[x]; }; var result = null;"
End If
scriptCtrl.ExecuteStatement "result = " & str & ";"
Set parseJSON = scriptCtrl.CodeObject.result
End Function
Function GetFile(sFileName)
Dim oFso, oFout
Set oFso = Server.CreateObject("Scripting.FileSystemObject")
If oFso.FileExists(Server.Mappath(sFileName)) Then
Set oFout = oFso.OpenTextFile(Server.Mappath(sFileName), 1, False)
On Error Resume Next
GetFile = oFout.ReadAll()
If Err Then
Err.Clear
GetFile = ""
End If
oFout.Close
Set oFout = Nothing
Else
GetFile = ""
End If
Set oFso = Nothing
End Function
%>
這2中可以根據(jù)不同情況進行采用