Android Question how to get letters below F

Makumbi

Active Member
Licensed User
Please help i have this json but my biggest problem is extracting only letters below F example ABCDEO from the list of points
B4X:
JSON Tree Example
Parse
[{"ACCOUNT":"05-05605","Name":"AMPUMUZA SHELLOMITH","Class":"S6","House":null,"Trm":"III","artscience":"AR","h15":"D2","h25":"C3","h35":"D2","GP":"F9","HISP":"","GPPoints":"F","PhyPoints":"F","GeogPoints":"F","EconPointst":"F","LitPoints":"A","IREPoints":"","LugPoints":"F","artpoints":"","FoodPoints":"F","TDPoints":"F","GermanPoints":"F","WoodPoints":"F","ArabPoints":"F","EnterprPoints":"F","SubMathPoints":"F","CompPOINTS":"F","Principle":6,"Subsidiary":0,"TotalPoints":6}]
0
EconPointst: F
artscience: AR
h35: D2
LugPoints: F
h15: D2
Trm: III
GermanPoints: F
TotalPoints: 6
Name: AMPUMUZA SHELLOMITH
ArabPoints: F
ACCOUNT: 05-05605
WoodPoints: F
SubMathPoints: F
Subsidiary: 0
GPPoints: F
FoodPoints: F
PhyPoints: F
TDPoints: F
EnterprPoints: F
GP: F9
House: null
h25: C3
GeogPoints: F
LitPoints: A
CompPOINTS: F
Principle: 6
artpoints:
Class: S6
IREPoints:
HISP:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim root As List = parser.NextArray
For Each colroot As Map In root
 Dim EconPointst As String = colroot.Get("EconPointst")
 Dim artscience As String = colroot.Get("artscience")
 Dim h35 As String = colroot.Get("h35")
 Dim LugPoints As String = colroot.Get("LugPoints")
 Dim h15 As String = colroot.Get("h15")
 Dim Trm As String = colroot.Get("Trm")
 Dim GermanPoints As String = colroot.Get("GermanPoints")
 Dim TotalPoints As Int = colroot.Get("TotalPoints")
 Dim Name As String = colroot.Get("Name")
 Dim ArabPoints As String = colroot.Get("ArabPoints")
 Dim ACCOUNT As String = colroot.Get("ACCOUNT")
 Dim WoodPoints As String = colroot.Get("WoodPoints")
 Dim SubMathPoints As String = colroot.Get("SubMathPoints")
 Dim Subsidiary As Int = colroot.Get("Subsidiary")
 Dim GPPoints As String = colroot.Get("GPPoints")
 Dim FoodPoints As String = colroot.Get("FoodPoints")
 Dim PhyPoints As String = colroot.Get("PhyPoints")
 Dim TDPoints As String = colroot.Get("TDPoints")
 Dim EnterprPoints As String = colroot.Get("EnterprPoints")
 Dim GP As String = colroot.Get("GP")
 Dim House As String = colroot.Get("House")
 Dim h25 As String = colroot.Get("h25")
 Dim GeogPoints As String = colroot.Get("GeogPoints")
 Dim LitPoints As String = colroot.Get("LitPoints")
 Dim CompPOINTS As String = colroot.Get("CompPOINTS")
 Dim Principle As Int = colroot.Get("Principle")
 Dim artpoints As String = colroot.Get("artpoints")
 Dim Class As String = colroot.Get("Class")
 Dim IREPoints As String = colroot.Get("IREPoints")
 Dim HISP As String = colroot.Get("HISP")
Next
 

emexes

Well-Known Member
Licensed User
As in, you only want the fields where the values are one of the six letters you specified?

That bit is no problem. What about the D2 and C3 etc? Are they regarded as being D and C?

Actually, I think we can go one better than you asked for. Hang on a sec.
 

DonManfred

Expert
Licensed User
1. http://basic4ppc.com:51042/json/index.html
2.
B4X:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim root As List = parser.NextArray
For Each colroot As Map In root
 Dim EconPointst As String = colroot.Get("EconPointst")
 Dim artscience As String = colroot.Get("artscience")
 Dim h35 As String = colroot.Get("h35")
 Dim LugPoints As String = colroot.Get("LugPoints")
 Dim h15 As String = colroot.Get("h15")
 Dim Trm As String = colroot.Get("Trm")
 Dim GermanPoints As String = colroot.Get("GermanPoints")
 Dim TotalPoints As Int = colroot.Get("TotalPoints")
 Dim Name As String = colroot.Get("Name")
 Dim ArabPoints As String = colroot.Get("ArabPoints")
 Dim ACCOUNT As String = colroot.Get("ACCOUNT")
 Dim WoodPoints As String = colroot.Get("WoodPoints")
 Dim SubMathPoints As String = colroot.Get("SubMathPoints")
 Dim Subsidiary As Int = colroot.Get("Subsidiary")
 Dim GPPoints As String = colroot.Get("GPPoints")
 Dim FoodPoints As String = colroot.Get("FoodPoints")
 Dim PhyPoints As String = colroot.Get("PhyPoints")
 Dim TDPoints As String = colroot.Get("TDPoints")
 Dim EnterprPoints As String = colroot.Get("EnterprPoints")
 Dim GP As String = colroot.Get("GP")
 Dim House As String = colroot.Get("House")
 Dim h25 As String = colroot.Get("h25")
 Dim GeogPoints As String = colroot.Get("GeogPoints")
 Dim LitPoints As String = colroot.Get("LitPoints")
 Dim CompPOINTS As String = colroot.Get("CompPOINTS")
 Dim Principle As Int = colroot.Get("Principle")
 Dim artpoints As String = colroot.Get("artpoints")
 Dim Class As String = colroot.Get("Class")
 Dim IREPoints As String = colroot.Get("IREPoints")
 Dim HISP As String = colroot.Get("HISP")
Next
 

emexes

Well-Known Member
Licensed User
Run this:
B4X:
Dim JS As String = $"["ACCOUNT":"05-05605","Name":"AMPUMUZA SHELLOMITH","Class":"S6","House":Null,"Trm":"III","artscience":"AR","h15":"D2","h25":"C3","h35":"D2","GP":"F9","HISP":"","GPPoints":"F","PhyPoints":"F","GeogPoints":"F","EconPointst":"F","LitPoints":"A","IREPoints":"","LugPoints":"F","artpoints":"","FoodPoints":"F","TDPoints":"F","GermanPoints":"F","WoodPoints":"F","ArabPoints":"F","EnterprPoints":"F","SubMathPoints":"F","CompPOINTS":"F","Principle":6,"Subsidiary":0,"TotalPoints":6]"$

Log(JS.Length)    'pessimists of the world, unite
Log(JS)
JS = "{" & JS.SubString2(1, JS.Length - 1) & "}"    'change array [] to object {}
Log(JS)
 
Dim parser As JSONParser
parser.Initialize(JS)

Dim OutputMap As Map = parser.NextObject
Log(OutputMap.Size)

Dim FieldName As String
Dim FieldValue As String

For I = 0 To OutputMap.Size - 1
    '''Log(OutputMap.GetKeyAt(I) & " = " & OutputMap.GetValueAt(I))
 
    FieldName = OutputMap.GetKeyAt(I)
    If FieldName.Trim.ToUpperCase.EndsWith("POINTS") Then
        FieldValue = OutputMap.GetValueAt(I)
     
        Select Case FieldValue.Trim.ToUpperCase
            Case "A", "B", "C", "D", "E", "O"
                Log(FieldName.Trim & " = " & FieldValue.Trim)
             
            Case "1", "2", "3", "4", "5", "6"
                Log("  (Numeric score for " & FieldName.Trim & ")")
                 
            Case "F"
                Log("  (No good at " & FieldName.Trim & ")")
             
        End Select
    End If
Next
and you should get this:
B4X:
475
["ACCOUNT":"05-05605","Name":"AMPUMUZA SHELLOMITH","Class":"S6","House":Null,"Trm":"III","artscience":"AR","h15":"D2","h25":"C3","h35":"D2","GP":"F9","HISP":"","GPPoints":"F","PhyPoints":"F","GeogPoints":"F","EconPointst":"F","LitPoints":"A","IREPoints":"","LugPoints":"F","artpoints":"","FoodPoints":"F","TDPoints":"F","GermanPoints":"F","WoodPoints":"F","ArabPoints":"F","EnterprPoints":"F","SubMathPoints":"F","CompPOINTS":"F","Principle":6,"Subsidiary":0,"TotalPoints":6]
{"ACCOUNT":"05-05605","Name":"AMPUMUZA SHELLOMITH","Class":"S6","House":Null,"Trm":"III","artscience":"AR","h15":"D2","h25":"C3","h35":"D2","GP":"F9","HISP":"","GPPoints":"F","PhyPoints":"F","GeogPoints":"F","EconPointst":"F","LitPoints":"A","IREPoints":"","LugPoints":"F","artpoints":"","FoodPoints":"F","TDPoints":"F","GermanPoints":"F","WoodPoints":"F","ArabPoints":"F","EnterprPoints":"F","SubMathPoints":"F","CompPOINTS":"F","Principle":6,"Subsidiary":0,"TotalPoints":6}
30
  (No good at LugPoints)
  (No good at GermanPoints)
  (Numeric score for TotalPoints)
  (No good at ArabPoints)
  (No good at WoodPoints)
  (No good at SubMathPoints)
  (No good at GPPoints)
  (No good at FoodPoints)
  (No good at PhyPoints)
  (No good at TDPoints)
  (No good at EnterprPoints)
  (No good at GeogPoints)
LitPoints = A
  (No good at CompPOINTS)
(I did using B4J but same should work in B4A)
 

emexes

Well-Known Member
Licensed User
Now that I've had a closer look at your first code, I think the problem there is that you're (re)dimming all the variables for each field (colroot) that you parse through, and so after you've done all of that and out of the For Each loop, your variables would be set to (mostly) blank except for the very last field, which escaped the Massacre at (re)Dim Hill.

ps: and I think Manfred's code might have a similar issue, so: you're in good company (he is The King of Code ;-)

pps: but he gave us the online parser tip too, which is a bit of a winner

ppps: except that I see it too needs it as an object rather than an array, so I'm feeling better about having done that in my example also :)
 
Last edited:

emexes

Well-Known Member
Licensed User
I'm impressed that you typed all that stuff, though :)

I usually bail out after I've typed a half-dozen similar lines, start looking for shortcuts, but when you're under pressure... we've all been there.
 

Makumbi

Active Member
Licensed User
I'm impressed that you typed all that stuff, though :)

I usually bail out after I've typed a half-dozen similar lines, start looking for shortcuts, but when you're under pressure... we've all been there.
long live man you have saved my day
 
Top