Android Question delete characters

Isac

Active Member
Licensed User
Longtime User
what do i want to do?

I retrieve this data from the server this way : [{"password":"ok"}]

I would like to see only ok , not [{"password":" "}]


B4X:
Sub JobDone (Job As HttpJob) 
    
    If Job.Success Then
    
    res = Job.GetString  
    Log("Back from Job:" & Job.JobName )
    Log("Response from server: " & res)
    
    Select Job.JobName
        Case "controllo"
          Label1.Text=res
            
            Log(Job.GetString)           
        End Select
    Else
        Log("Error: " & Job.ErrorMessage)
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
    
    Dim parser As JSONParser
    parser.Initialize(res)

End Sub



PHP:
$action = $_GET["action"];
switch ($action)
{
case 'controllo':
$q=mysql_query("SELECT password FROM tbl_member");
$rows = array();
while($r = mysql_fetch_assoc($q))
{
  $rows[] = $r;
}
print json_encode($rows);
break;
}
 

udg

Expert
Licensed User
Longtime User
Use this tool to parse a JSON string and have the corresponding B4X code.
For string "[{"password":"ok"}]" it gives:

B4X:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim root As List = parser.NextArray
For Each colroot As Map In root
 Dim password As String = colroot.Get("password")
Next
 
Upvote 0
Top