PowerBuilder
PowerBuilder
JSON Estimote Data
See more JSON Examples
Demonstrates accessing some data from an Estimote REST API response. The Estimate REST API responds with a JSON array (i.e. something beginning with "[" and ending with "]"). To parse, this must be made into a JSON object by prepending "{"*":" and appending "}".This example uses the following JSON object:
{"*":[{
"id" : "B9407F30-F5F8-466E-AFF9-25556B57FE6D:28203:50324",
"uuid" : "B9407F30-F5F8-466E-AFF9-25556B57FE6D",
"major" : 28203,
"minor" : 50324,
"mac" : "dd6fc4946e2b",
"settings" : {
"battery" : 100,
"interval" : 950,
"hardware" : "D3.4",
"firmware" : "A3.2.0",
"basic_power_mode" : true,
"smart_power_mode" : true,
"timezone" : "America/Los_Angeles",
"security" : false,
"motion_detection" : true,
"latitude": 37.7979,
"longitude": -122.4408,
"conditional_broadcasting" : "flip to stop",
"broadcasting_scheme" : "estimote",
"range" : -12,
"power" : -12,
"firmware_deprecated" : false,
"firmware_newest" : true,
"location" : null
},
"color" : "blueberry",
"context_id" : 339488,
"name" : "blueberry ibeacon1",
"battery_life_expectancy_in_days" : 1377,
"tags" : []
}, {
"id" : "B9407F30-F5F8-466E-AFF9-25556B57FE6D:25845:21739",
"uuid" : "B9407F30-F5F8-466E-AFF9-25556B57FE6D",
"major" : 25845,
"minor" : 21739,
"mac" : "ff5454eb64f5",
"settings" : {
"battery" : 100,
"interval" : 950,
"hardware" : "D3.4",
"firmware" : "A3.2.0",
"basic_power_mode" : false,
"smart_power_mode" : true,
"timezone" : "America/Los_Angeles",
"security" : false,
"motion_detection" : true,
"conditional_broadcasting" : "flip to stop",
"broadcasting_scheme" : "estimote",
"range" : -12,
"power" : -12,
"firmware_deprecated" : false,
"firmware_newest" : true,
"location" : null
},
"color" : "blueberry",
"context_id" : 339483,
"name" : "blueberry2",
"battery_life_expectancy_in_days" : 1168,
"tags" : []
}
]}
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Json
integer li_BatteryVal
string ls_TimeZone
integer li_RangeVal
string ls_LongitudeStr
li_Success = 0
loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
if li_rc < 0 then
destroy loo_Json
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Json.EmitCompact = 0
// Assume the file contains the data as shown above..
li_Success = loo_Json.LoadFile("qa_data/json/estimote.json")
if li_Success <> 1 then
Write-Debug loo_Json.LastErrorText
destroy loo_Json
return
end if
// To get the value for "settings.battery" for the 1st array object:
li_BatteryVal = loo_Json.IntOf("*[0].settings.battery")
Write-Debug "battery: " + string(li_BatteryVal)
// To get the value for "settings.timezon" for the 1st array object:
ls_TimeZone = loo_Json.StringOf("*[0].settings.timezone")
Write-Debug "timezone: " + ls_TimeZone
// To get the "settings.range" for the 2nd array object:
li_RangeVal = loo_Json.IntOf("*[1].settings.range")
Write-Debug "range: " + string(li_RangeVal)
// To get the "settings.longitude" for the 1st array object:
// Note: Any primitie value can be retrieved as as string: integers, floating point numbers, booleans, etc.
ls_LongitudeStr = loo_Json.StringOf("*[0].settings.longitude")
Write-Debug "longitude: " + ls_LongitudeStr
destroy loo_Json