Linux, FB 1.06
The typical String:
Code: Select all
{"system":{"get_sysinfo":{"sw_ver":"1.5.5 Build 181225 Rel.102720","hw_ver":"2.0","type":"IOT.SMARTPLUGSWITCH","model":"HS110(AU)","mac":"B0:BE:76:C1:B8:3C","dev_name":"Smart Wi-Fi Plug With Energy Monitoring","alias":" Device1","relay_state":1,"on_time":6949,"active_mode":"none","feature":"TIM:ENE","updating":0,"icon_hash":"","rssi":-25,"led_off":0,"longitude_i":0,"latitude_i":0,"hwId":"A28C8BB92AFCB6CAFB83A8C00145F7E2","fwId":"00000000000000000000000000000000","deviceId":"80061922201888E1FBE72378A55A2C581ADF3EAA","oemId":"6480C2101948463DC65D7009CAECDECC","next_action":{"type":-1},"err_code":0}}}
After each : (colon) there is a string that I am interested in.
For example: "hw_ver":"2.0" , I am interested in 2.0
How I went about it.
1. Replaced each comma with a LF, and then stripped all of the undesirable char's. ie: " { }
which results in this.
Code: Select all
system:get_sysinfo:sw_ver:1.5.5 Build 181225 Rel.102720
hw_ver:2.0
type:IOT.SMARTPLUGSWITCH
model:HS110(AU)
mac:B0:BE:76:C1:B8:3C
dev_name:Smart Wi-Fi Plug With Energy Monitoring
alias: Device1
relay_state:1
on_time:6949
active_mode:none
feature:TIM:ENE
updating:0
icon_hash:
rssi:-25
led_off:0
longitude_i:0
latitude_i:0
hwId:A28C8BB92AFCB6CAFB83A8C00145F7E2
fwId:00000000000000000000000000000000
deviceId:80061922201888E1FBE72378A55A2C581ADF3EAA
oemId:6480C2101948463DC65D7009CAECDECC
next_action:type:-1
err_code:0
Next I want to capture all the char's after the colon : but before the next LF.
That's where I get into trouble, the (Segmentation fault (core dumped)) kind of trouble.
Each time I replace a Comma, I remembered the position with LFCnt.LF(X):
Code: Select all
With LFCnt
.LF(1) = 1
Dim X as Integer
For X = 1 to 23
Control.Cnt = Instr(Temp,",")
If Control.Cnt > 0 Then
Mid(Temp,Control.Cnt) = Chr(&H0A)
.LF(X) = Control.Cnt
.dString(X) = Mid(Temp,.LF(X-1)+1,(.LF(X)-.LF(X-1))-1)
Else
Exit For
EndIf
Next
.dString(X) = Right(Temp,10) 'Last Char of Temp
End With
That all seems to work (which the printing shows) but for the Segmentation error that can happen anywhere.
I have modified the code for days:
Using String * n instead of just String
Using zString * n
Expanding the dString(X) = statement into 3 or 4 steps.
All to no avail.
I am sure there are String guru's here, and would love to hear what I am doing wrong , OR what other way to do it.
Regards