Advise on how to read the following json file

Post

Posted
Rating:
#1 (In Topic #1210)
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
Hi all

I have the following line coming in from my Server

Code (gambas)

  1. \{"messages":\{"transactionId":["Invalid value: 5be3f476-f73e-4968-9ea5-721f622eaca2"]}}

but I can not seem to work out how I read in the information from the "transactionId"

i have this so far (and this works in other areas of my code

Code (gambas)

  1. Private Sub GetStatusMessagesEOD(http As HttpClient)
  2.  
  3.     global.buffer = Null
  4.  
  5.     If http.Status < 0 Then
  6.         Global.addtoStatusList("Sorry a error was detected")
  7.     Else
  8.         ' Success - read data
  9.         If Lof(http) Then Read #http, global.buffer, Lof(http)
  10.  
  11.         Dim vNew As Variant = JSON.Decode(global.buffer)
  12.        
  13.         global.AddToDebugList(global.buffer)
  14.         Debug global.buffer
  15.        
  16.  
  17.        
  18.         If InStr(global.buffer, "error") Then
  19.             Global.addtoStatusList("Terminal Offline or a Error has happened")
  20.             MessageFunctions.SendToPoSterminal("Status|OFFLINE")
  21.             'SendtoPoS Offline to PinPad (Show PoS would show the Chip&Pin Icon with the cross though it)
  22.            
  23.         Else
  24.             Select Case LCase(vNew["messages"])
  25.                 Case "transactionid"
  26.                     Debug vNew["transactionId"][1]
  27.             End Select  
  28.         End If      
  29.     End If

I need to send the "Invalid value: 5be3f476-f73e-4968-9ea5-721f622eaca2" back to my user as a message on screen but i can not for the love of me work this one out (sorry but my brain has given up today) maybe a fresh pair of eyes will help

Many thanks in advance

Andy
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
transactionid is an array of string[] and it is only one string , it is not a collection or an array so [1] does not exist

it is "Invalid value: 5be3f476-f73e-4968-9ea5-721f622eaca2"

EDIT:  Also "messages" is a collection so you are inspecting it wrong.

You want something more like this…

Code (gambas)

  1.  
  2. For Each sKey In vNew["messages"].Keys  ' its a collection so read it as a collection
  3.   Select LCase(sKey)
  4.     Case "transactionid"
  5.       sKey = vNew["messages"][sKey][0] ' get the data and find the name , data
  6.       sName = Mid(sKey, 1, InStr(sKey, ":") - 1)
  7.       sData = Mid(sKey, InStr(sKey, ":") + 2)
  8.       Debug sName, sData
  9.  
Online now: No Back to the top
1 guest and 0 members have just viewed this.