Android Question Validate JSON content

rscheel

Well-Known Member
Licensed User
Longtime User
I'm capturing a Json, but sometimes the variable "liveWeight" is wrong, for example

JSON OK

B4X:
JSON: {"type":"1","state":"6","subState":"0","stateStatus":"0","version":"20140829","batteryStatus":"5","RSSI":"1","scaleID":"46166464","buttonStates":"0","liveWeight":"0","liveStdError":"0","liveTimeStamp":"30154","autoWeight":"0","autoStdError":"0","autoID":"0","autoTimeStamp":"0","parameters":["2","50","3000","200","0","0","5","1000000","0","-1","-1","-1","-1","-1","-1","-1","20151119","50014","20081605","-1"],"information":"","rawData":""}
liveWeight: 0

JSON ERROR

B4X:
JSON: {"type":"1","state":"6","subState":"0","stateStatus":"0","version":"20140829","batteryStatus":"5","RSSI":"1","scaleID":"461iveWeight":"0","liveStdError":"0","liveTimeStamp":"31155","autoWeight":"0","autoStdError":"0","autoID":"0","autoTimeStamp":"0","parameters":["2","50","3000","200","0","0","5","1000000","0","-1","-1","-1","-1","-1","-1","-1","20151119","50014","20081605","-1"],"information":"","rawData":""}

As we can see the variable "liveWeight": "0", it is enriched in the value of "scaleID": "461iveWeight": "0"

How can I validate that it comes in json liveWeight before showing its value?

B4X:
JSON.Initialize(J)
    Mapa = JSON.NextObject
    Log("liveWeight: " & Mapa.Get("liveWeight"))
 

rscheel

Well-Known Member
Licensed User
Longtime User
SOLVED

B4X:
    If Mapa.ContainsKey("liveWeight") Then
        Log("liveWeight: " & Mapa.Get("liveWeight"))
    Else
        Log("La variable no existe")
    End If
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…