WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

MSScriptControl

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

udfGetJSONValue

 Keywords: udfGetJSONValue Get JSOn Value Keyname Node Eval JScript MSScriptControl.ScriptControl 

DirChange (DirScript ())

#DefineFunction udfGetJSONValue (strJSONData, strJSONKey)
If strJSONData == "" Then Return ""
objJSC = CreateObject ("MSScriptControl.ScriptControl")
objJSC.Language = "JScript"
Return objJSC.Eval(: strJSONData : `.` : strJSONKey)
#EndFunction


strFileJSON = "JSON.txt"
If FileExist (strFileJSON) == 0
   ;http://gomashup.com/cms/usa_zipcode_json
   stateabrv = "WA"
   cURL = "http://gomashup.com/json.php?fds=geo/usa/zipcode/state/" : stateabrv : "&jsoncallback"
   oHTTP = CreateObject ("WinHttp.WinHttpRequest.5.1")
   oHTTP.Open("GET", cURL, @FALSE)
   oHTTP.Send()
   FilePut (strFileJSON, oHTTP.ResponseText)
   oHTTP = 0
EndIf

strJSONData = FileGet ("JSON.txt")
; Pause("JSON DATA",strJSONData)

intItems = udfGetJSONValue (strJSONData, "result.length")

strJSONKey = "result[0].City"
strJSONValue = udfGetJSONValue (strJSONData, strJSONKey)
Pause ("Demo|udfGetJSONValue", "Data = " : StrSub (strJSONData, 1, 300) : @LF : "Items = " : intItems : @LF : "Key = " : strJSONKey : @LF : "Value = " : strJSONValue)

strJSONKey = "result[" : intItems - 1 : "].City"
strJSONValue = udfGetJSONValue (strJSONData, strJSONKey)
Pause ("Demo|udfGetJSONValue", "Data = " : StrSub (strJSONData, 1, 300) : @LF : "Items = " : intItems : @LF : "Key = " : strJSONKey : @LF : "Value = " : strJSONValue)
Exit

Article ID:   W17966
Filename:   udfGetJSONValue.txt
File Created: 2012:04:19:09:42:10
Last Updated: 2012:04:19:09:42:10