|
ASP Xtreme Evolution
|
JsonThis Class goal is to provide a simple way to parse JSON (JavaScript Object Notation) data directly from vbscript. Notes
About
Summary
getElement
This function takes a dot separated path and look for the element value in the JSON. Parameters
Returns
Exampledim sJson, oJson sJson = "" & _ "{" & vbCrLf & _ " 'hello' : 'Hello World !'," & vbCrLf & _ " 'howdy' : 'How do you do ?'," & vbCrLf & _ " 'fields' : {" & vbCrLf & _ " 'one': 1," & vbCrLf & _ " 'two': 2," & vbCrLf & _ " 'three': 3" & vbCrLf & _ " }" & vbCrLf & _ "};" set oJson = new Json oJson.loadJson(sJson) Response.write(oJson.getElement("hello") & "<br />" & vbCrLf) Response.write(oJson.getElement("howdy") & "<br />" & vbCrLf) set oJson = nothing getChildNodes
Look for all element child keys and enumerate them. Parameters
Returns
Exampledim sJson, oJson, key sJson = "" & _ "{" & vbCrLf & _ " 'hello' : 'Hello World !'," & vbCrLf & _ " 'howdy' : 'How do you do ?'," & vbCrLf & _ " 'fields' : {" & vbCrLf & _ " 'one': 1," & vbCrLf & _ " 'two': 2," & vbCrLf & _ " 'three': 3" & vbCrLf & _ " }" & vbCrLf & _ "};" set oJson = new Json oJson.loadJson(sJson) for each key in oJson.getChildNodes("") Response.write(key & " : " & oJson.getElement(key) & "<br />" & vbCrLf) next set oJson = nothing |
Since ASP Classes strangely doesn’t accept parameters at it’s initializa- tion.
public sub loadJson( sJson )
This function takes a dot separated path and look for the element value in the JSON.
public function getElement( sPath )
Look for all element child keys and enumerate them.
public function getChildNodes( sPath )