Wish Root variable conflict in JSON Tree Example

Lucas Siqueira

Active Member
Licensed User
Longtime User
when working with b4xpages there is already a declared root variable.
it always conflicts when we convert the code in the JSON Tree Example


Change:
M if it is Map
L if it is List


B4X:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim root As Map = parser.NextObject
Dim token As String = root.Get("token")

Update to:
B4X:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim m As Map = parser.NextObject
Dim token As String = m.Get("token")
 

TILogistic

Expert
Licensed User
Longtime User
or use (AS)
B4X:
    Dim sText As String = $"{"token":"NTE3NzUzZmU3Yjk4ZDdjMmQ1YmQ0MzZjYzE0NThmMzBiNDhhZTBjOGJiMmUwYmU3MTY0MDM4NTAwOA=="}"$
    Log(sText.As(JSON).ToMap.Get("token"))
    Log(sText.As(JSON).ToMap.As(JSON).ToString)

1640957801191.png
 

Lucas Siqueira

Active Member
Licensed User
Longtime User
i know i can use this .AS(Type) option, i always fix the code i copy there from json. I don't have a problem with that myself.

but teaching b4xpages to new users, they get confused in using the feature, because it's not just copy and put, you have to modify
 

TILogistic

Expert
Licensed User
Longtime User
or update tools Json tree (B4J)
or Jserver
 
Top