decript string...

User avatar
sal21
PlatinumLounger
Posts: 4266
Joined: 26 Apr 2010, 17:36

decript string...

Post by sal21 »

Based this string how to decript????

data=%5Bout%3Acsv%28comune%2C%20provincia%2C%20name%2C%20highway%2C%20%3A%3Alat%2C%3A%3Alon%3Btrue%3B%22%3B%22%29%5D%5Btimeout%3A600%5D%3B%0A%2F%2Fprovincia%20da%20cui%20estrarre%20i%20dati%0Aarea%5Bboundary%3Dadministrative%5D%5B%22admin_level%22%3D6%5D%5Bname~%22%5Epesaro%22%2Ci%5D-%3E.searchArea%3B%0Arelation%5Bboundary%3Dadministrative%5D%5B%22admin_level%22%3D8%5D%28area.searchArea%29%3B%0Aforeach%20%28%0A%20%20map_to_area-%3E.comune%3B%0A%20%20make%20stat%20comune%3Dcomune.set%28t%5B%22name%22%5D%29%2Cprovincia%3DsearchArea.set%28t%5B%22short_name%22%5D%29%3B%0A%20%20out%3B%0A%20%20way%5Bhighway~%22residential%7Cunclassified%7Ctertiary%7Csecondary%7Cprimary%22%5D%5Bname%5D%28area.comune%29%3B%0A%20%20out%20center%3B%0A%29%3B%0A"

User avatar
HansV
Administrator
Posts: 77256
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: decript string...

Post by HansV »

You can replace the hexadecimal characters using the function

Code: Select all

Function ReplaceChars(ByVal s As String) As String
    Dim i As Long
    Do
        i = InStrRev(s, "%")
        If i = 0 Then Exit Do
        s = Left(s, i - 1) & Chr("&H" & Mid(s, i + 1, 2)) & Mid(s, i + 3)
    Loop
    ReplaceChars = s
End Function
but what you do with the result is up to you...
Regards,
Hans

snb
4StarLounger
Posts: 442
Joined: 14 Nov 2012, 16:06

Re: decript string...

Post by snb »

Code: Select all

Sub M_snb()
  c00 = "%5Bout%3Acsv%28comune%2C%20provincia%2C%20name%2C%20highway%2C%20%3A%3Alat%2C%3A%3Alon%3Btrue%3B%22%3B%22%29%5D%5Btimeout%3A600%5D%3B%0A%2F%2Fprovincia%20da%20cui%20estrarre%20i%20dati%0Aarea%5Bboundary%3Dadministrative%5D%5B%22admin_level%22%3D6%5D%5Bname~%22%5Epesaro%22%2Ci%5D-%3E.searchArea%3B%0Arelation%5Bboundary%3Dadministrative%5D%5B%22admin_level%22%3D8%5D%28area.searchArea%29%3B%0Aforeach%20%28%0A%20%20map_to_area-%3E.comune%3B%0A%20%20make%20stat%20comune%3Dcomune.set%28t%5B%22name%22%5D%29%2Cprovincia%3DsearchArea.set%28t%5B%22short_name%22%5D%29%3B%0A%20%20out%3B%0A%20%20way%5Bhighway~%22residential%7Cunclassified%7Ctertiary%7Csecondary%7Cprimary%22%5D%5Bname%5D%28area.comune%29%3B%0A%20%20out%20center%3B%0A%29%3B%0A"

  sn = Split(c00, "%")
  
  For j = 1 To UBound(sn)
    sn(j) = Mid(sn(j), 3)
  Next
  
  MsgBox Application.Trim(Join(sn))
End Sub

User avatar
sal21
PlatinumLounger
Posts: 4266
Joined: 26 Apr 2010, 17:36

Re: decript string...

Post by sal21 »

HansV wrote:
14 Sep 2023, 16:56
You can replace the hexadecimal characters using the function

Code: Select all

Function ReplaceChars(ByVal s As String) As String
    Dim i As Long
    Do
        i = InStrRev(s, "%")
        If i = 0 Then Exit Do
        s = Left(s, i - 1) & Chr("&H" & Mid(s, i + 1, 2)) & Mid(s, i + 3)
    Loop
    ReplaceChars = s
End Function
but what you do with the result is up to you...
really my code is:

Code: Select all


Sub TEST_JSON_PARSE()

'verificare
'https://data.opendatasoft.com/explore/dataset/rifter_civici_pt%40bologna/export/

    'myurl = "https://overpass-api.de/api/interpreter?data=%5Bout%3Acsv%28comune%2C%20provincia%2C%20name%2C%20highway%2C%20%3A%3Alat%2C%3A%3Alon%3Btrue%3B%22%3B%22%29%5D%5Btimeout%3A600%5D%3B%0A%2F%2Fprovincia%20da%20cui%20estrarre%20i%20dati%0Aarea%5Bboundary%3Dadministrative%5D%5B%22admin_level%22%3D6%5D%5Bname~%22%5Enapoli%22%2Ci%5D-%3E.searchArea%3B%0Arelation%5Bboundary%3Dadministrative%5D%5B%22admin_level%22%3D8%5D%28area.searchArea%29%3B%0Aforeach%20%28%0A%20%20map_to_area-%3E.comune%3B%0A%20%20make%20stat%20comune%3Dcomune.set%28t%5B%22name%22%5D%29%2Cprovincia%3DsearchArea.set%28t%5B%22short_name%22%5D%29%3B%0A%20%20out%3B%0A%20%20way%5Bhighway~%22residential%7Cunclassified%7Ctertiary%7Csecondary%7Cprimary%22%5D%5Bname%5D%28area.comune%29%3B%0A%20%20out%20center%3B%0A%29%3B%0A"

    
    Dim xmlhttp As New MSXML2.XMLHTTP60, myurl As String
    
    myurl = "https://overpass-api.de/api/interpreter?data=%5Bout%3Acsv%28comune%2C%20provincia%2C%20name%2C%20highway%2C%20%3A%3Alat%2C%3A%3Alon%3Btrue%3B%22%3B%22%29%5D%5Btimeout%3A600%5D%3B%0A%2F%2Fprovincia%20da%20cui%20estrarre%20i%20dati%0Aarea%5Bboundary%3Dadministrative%5D%5B%22admin_level%22%3D6%5D%5Bname~%22%5Epesaro%22%2Ci%5D-%3E.searchArea%3B%0Arelation%5Bboundary%3Dadministrative%5D%5B%22admin_level%22%3D8%5D%28area.searchArea%29%3B%0Aforeach%20%28%0A%20%20map_to_area-%3E.comune%3B%0A%20%20make%20stat%20comune%3Dcomune.set%28t%5B%22name%22%5D%29%2Cprovincia%3DsearchArea.set%28t%5B%22short_name%22%5D%29%3B%0A%20%20out%3B%0A%20%20way%5Bhighway~%22residential%7Cunclassified%7Ctertiary%7Csecondary%7Cprimary%22%5D%5Bname%5D%28area.comune%29%3B%0A%20%20out%20center%3B%0A%29%3B%0A"
    'oppure senza autorizzazione
    'https://samurai016.github.io/Comuni-ITA/#tag/comuni
    'myurl = "https://axqvoqvbfjpaamphztgd.functions.supabase.co/comuni"
    
    'ReplaceChars myurl
    
    With xmlhttp
        
        .Open "GET", myurl, False
        '.setRequestHeader "Authorization", "Bearer 6357ac75baecf33196160c21"
        .send
        Debug.Print .responseText
        
        Dim Handle As Integer
        Handle = FreeFile
        Open "C:\Lavori_Vb6\REST_API_OPENAPI\JSON_FILE\comuni.txt" For Output As #Handle
        Print #Handle, .responseText
        Close #Handle
        
        Call LEGGI_JSON_FILE
        
        'ReadFile "C:\Lavori_Vb6\REST_API_OPENAPI\JSON_FILE\PROVINCE.txt"
        
    End With
    
End Sub
whe i pass the myurl to the api rest in debug.print t .responseText have a correct result in csv.

but i need to replace the bologna city with other... similar napoli

User avatar
SpeakEasy
4StarLounger
Posts: 451
Joined: 27 Jun 2021, 10:46

Re: decript string...

Post by SpeakEasy »

Pretty sure there is an API call that can do this fairly simply, UrlUnescapeA. Sadly I'm currently on holiday, and nowhere near a PC so can't provide an example.

You could also leverage javascript's UnEscape function
Last edited by SpeakEasy on 15 Sep 2023, 21:52, edited 1 time in total.

User avatar
sal21
PlatinumLounger
Posts: 4266
Joined: 26 Apr 2010, 17:36

Re: decript string...

Post by sal21 »

SpeakEasy wrote:
15 Sep 2023, 21:43
Pretty sure there is an API call that can do this fairly simply, UrlUnescapeA. Sadly I'm currently on holiday, and nowhere near a PC so can't provide an example.
Ok

snb
4StarLounger
Posts: 442
Joined: 14 Nov 2012, 16:06

Re: decript string...

Post by snb »


User avatar
SpeakEasy
4StarLounger
Posts: 451
Joined: 27 Jun 2021, 10:46

Re: decript string...

Post by SpeakEasy »

Ok, so here's a possible API solution...

Code: Select all

Option Explicit

Private Declare Function UrlUnescape Lib "shlwapi" Alias "UrlUnescapeA" (ByVal pszURL As String, ByVal pszUnescaped As String, pcchUnescaped As Long, ByVal dwFlags As Long) As Long
Private Const URL_DONT_ESCAPE_EXTRA_INFO As Long = &H2000000

Public Function Decode(strDecodeMe As String) As String
    Dim strResult As String
    Dim mychars As Long
    
    strResult = Space(Len(strDecodeMe))
    mychars = Len(strDecodeMe)
    If UrlUnescape(strDecodeMe, strResult, mychars, URL_DONT_ESCAPE_EXTRA_INFO) = 0 Then Decode = Left(strResult, mychars)
End Function

User avatar
sal21
PlatinumLounger
Posts: 4266
Joined: 26 Apr 2010, 17:36

Re: decript string...

Post by sal21 »

SpeakEasy wrote:
23 Sep 2023, 13:06
Ok, so here's a possible API solution...

Code: Select all

Option Explicit

Private Declare Function UrlUnescape Lib "shlwapi" Alias "UrlUnescapeA" (ByVal pszURL As String, ByVal pszUnescaped As String, pcchUnescaped As Long, ByVal dwFlags As Long) As Long
Private Const URL_DONT_ESCAPE_EXTRA_INFO As Long = &H2000000

Public Function Decode(strDecodeMe As String) As String
    Dim strResult As String
    Dim mychars As Long
    
    strResult = Space(Len(strDecodeMe))
    mychars = Len(strDecodeMe)
    If UrlUnescape(strDecodeMe, strResult, mychars, URL_DONT_ESCAPE_EXTRA_INFO) = 0 Then Decode = Left(strResult, mychars)
End Function
tks.
but i cannot test now.