Android Question List to array

Schakalaka

Active Member
Licensed User
Longtime User
Hello.
on my app, i read a txt file, and i need to pass it in a http job with a api.
i need to "convert" the list into array, and/or this formant: (A,B,C,D,etc)

the http job string, will be:
"https://example.com/api/folder/" & the content of the list as "Array" with value as (A,B,C,D,etc) & "/something else.

some suggestions?
 

Mahares

Expert
Licensed User
Longtime User
some suggestions?
There are few ways. Here are some links:

 
Upvote 0

Schakalaka

Active Member
Licensed User
Longtime User
Thanks for your fast reply, but i don t understand how to use the code:

the app use an api, for check email addresses.
i'm try to use it in "Mass version"
More info: https://disify.com/
Doc: https://docs.disify.com/



B4X:
Sub StartButton_Click

listX (as list)   = File.ReadList(inputpath, "Email_List.txt")





        Dim j As HttpJob
        j.initialize("",Me)
        j.Download("https://disify.com/api/email/" & here: [email1,email2,email3,etc] as string & "/mass")
        wait for (j) jobDone (j As HttpJob)
        j.GetRequest.Timeout = 60000
        If j.success Then
        Log(j.GetString)
        Dim parser As JSONParser
        parser.Initialize(j.GetString)
        Dim root As Map = parser.NextObject
        Dim domain As String = root.Get("domain")
        Dim format As String = root.Get("format")
        Dim dns As String = root.Get("dns")
        Dim disposable As String = root.Get("disposable")
           
   
        Else
           
            Log("Error: " & j.ErrorMessage    )
       
        End If

        j.Release
   

   
End Sub
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
B4X:
private finalString as string
for i=0 to yourList.size-1
finalString=finalString&","&yourList.get(i)
next
finalString=finalString.substring(1)
Dim j As HttpJob
j.initialize("",Me)
j.Download("https://disify.com/api/email/" & finalString& "/mass")

However, I'm not sure if the above is the correct way. I think this is OK:
B4X:
private finalString as string
for i=0 to yourList.size-1
finalString=finalString&","&yourList.get(i)
next
finalString=finalString.substring(1)
private su as stringUtils
finalString=su.encodeUrl(finalString,"UTF8")
Dim j As HttpJob
j.initialize("",Me)
j.postString("https://disify.com/api/email/","email="&finalString&"&mass"))
 
Last edited:
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
don't forget the hidden field: bulk=true
also, above code doesn't seem to have a separator between each e-mail address. a comma may do, but i'd go for either a newline or carriage return + newline. you may have to try both (b4a's CRLF will get you chr(10) only).
also, if the list is long, stringbuilder is better than concatenating finalString
 
Upvote 0

Schakalaka

Active Member
Licensed User
Longtime User
thanks you!
the first code is working, but the problem is that there are too many email addresses and the passed url become too much long and return http error 414

?


Need to find another way ? ? ?
 
Upvote 0

Schakalaka

Active Member
Licensed User
Longtime User
i have find this solution:
i check each email and on result, i put&remove it in another list, or remove it from listX. At the end i create a new txt file with clean list

but return an ERROR before finish it:
java.lang.IndexOutOfBoundsException: Index 500 out of bounds for length 500

B4X:
Dim newlistX As List

newlistX.Initialize

    For i = 0 To listX.Size-1

        thisemail = listX.Get(i) [B]this line have the error[/B]

        
        Dim j As HttpJob
        j.initialize("",Me)
        j.Download("https://disify.com/api/email/" & thisemail)
        j.GetRequest.Timeout = 60000
        wait for (j) jobDone (j As HttpJob)
        If j.success Then
            Log(j.GetString)
            Dim parser As JSONParser
            parser.Initialize(j.GetString)
            Dim root As Map = parser.NextObject
            Dim domain As String = root.Get("domain")
            Dim format As String = root.Get("format")
            Dim dns As String = root.Get("dns")
            Dim whitelist As String = root.Get("whitelist")
            Dim disposable As String = root.Get("disposable")
            
            If format = True And dns = True And disposable = False Then
            newlistX.Add(thisemail)
            listX.RemoveAt(i)       

            Else
                
                listX.RemoveAt(i)   
                
                
            End If
   
        Else           
            Log("Error: " & j.ErrorMessage    )
        
        End If

        j.Release
    
        ProgressBar1.Progress = 100/(listX.Size)
    
    Next

    File.WriteList(outputpath,"TrueEmails.txt",newlistX)
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
thanks you!
the first code is working, but the problem is that there are too many email addresses and the passed url become too much long and return http error 414

?


Need to find another way ? ? ?


it cannot be done as a job.download or job download2. it must be a poststring. follow mc73's code and my suggestions.
 
Upvote 0

Similar Threads

Top