Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Node.js) JSON Estimote DataDemonstrates 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" : [] } ]}
var os = require('os'); if (os.platform() == 'win32') { if (os.arch() == 'ia32') { var chilkat = require('@chilkat/ck-node21-win-ia32'); } else { var chilkat = require('@chilkat/ck-node21-win64'); } } else if (os.platform() == 'linux') { if (os.arch() == 'arm') { var chilkat = require('@chilkat/ck-node21-arm'); } else if (os.arch() == 'x86') { var chilkat = require('@chilkat/ck-node21-linux32'); } else { var chilkat = require('@chilkat/ck-node21-linux64'); } } else if (os.platform() == 'darwin') { if (os.arch() == 'arm64') { var chilkat = require('@chilkat/ck-node21-mac-m1'); } else { var chilkat = require('@chilkat/ck-node21-macosx'); } } function chilkatExample() { var json = new chilkat.JsonObject(); json.EmitCompact = false; // Assume the file contains the data as shown above.. var success = json.LoadFile("qa_data/json/estimote.json"); if (success !== true) { console.log(json.LastErrorText); return; } // To get the value for "settings.battery" for the 1st array object: var batteryVal = json.IntOf("*[0].settings.battery"); console.log("battery: " + batteryVal); // To get the value for "settings.timezon" for the 1st array object: var timeZone = json.StringOf("*[0].settings.timezone"); console.log("timezone: " + timeZone); // To get the "settings.range" for the 2nd array object: var rangeVal = json.IntOf("*[1].settings.range"); console.log("range: " + 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. var longitudeStr = json.StringOf("*[0].settings.longitude"); console.log("longitude: " + longitudeStr); } chilkatExample(); |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.