PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV Mobile 2024 → Everything you wanted to know about JSON in Windev Mobile more was ashamed to ask (Tudo o que vc queria saber sobre JSON no Windev Mobile mais tinha vergonha de perguntar)
Everything you wanted to know about JSON in Windev Mobile more was ashamed to ask (Tudo o que vc queria saber sobre JSON no Windev Mobile mais tinha vergonha de perguntar)
Débuté par adrianoboller, 12 déc. 2014 15:06 - 9 réponses
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 12 décembre 2014 - 15:06
Everything you wanted to know about JSON in Windev Mobile more was ashamed to ask (Tudo o que vc queria saber sobre JSON no Windev Mobile mais tinha vergonha de perguntar)

Example 1

// Life Tech 29/10/2014
// Summary: converte a sequencia Escape '\' usada em Json para Ansi
// Syntax:
//[ <Result> = ] JsonToAnsi (<TextoJson>)
//
// Parameters:
// TextoJson: texto Json
// Return Value:
// UNICODE string:
// texto Ansi
PROCEDURE JsonToAnsi(TextoJson)

res is string

iniciouString is boolean

i is int=1

LOOP

IF i > Length(TextoJson) THEN BREAK

IF TextoJson[[i]]="""" THEN

iniciouString=1-iniciouString ; res+=""""; i++

ELSE

IF iniciouString THEN // dentro do "string"

IF TextoJson[[i]]="\" AND i<Length(TextoJson) THEN // dentro da sequencia Escape "\"

SWITCH TextoJson[[i+1]]

CASE """" : res+="""" ; i+=2 // quotation mark

CASE "\" : res+="\" ; i+=2 // reverse solidus

CASE "/" : res+="/" ; i+=2 // solidus

CASE "b" : res+="<" ; i+=2 // backspace

CASE "f" : res+=CR+CR ; i+=2 // formfeed

CASE "n" : res+=CR ; i+=2 // new line

CASE "r" : res+=CR ; i+=2 // carriage return

CASE "t" : res+=TAB ; i+=2 // horizontal Tab

CASE "u" : // hexadecimal digits \u1234

IF i+5 <= Length(TextoJson) THEN

res+=Charact(HexaToInt(TextoJson[[i+2 TO i+5]]))

i+=6

END

OTHER CASE

res+=TextoJson[[i]]; i++

END

ELSE // fora da sequencia Escape "\"

res+=TextoJson[[i]]; i++

END

ELSE // fora do "string"

res+=TextoJson[[i]]; i++

END

END

END

RESULT res
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 12 décembre 2014 - 15:11
Trace(VariantToJSON(Person))
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 12 décembre 2014 - 15:26
Tem até uma função JSONTOVARIANT

ou o reverso

Person is Variant
Person.LastName = "MOORE"
Person.FirstName = "Vince"

Trace(VariantToJSON(Person))
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 12 décembre 2014 - 15:26
PROCEDURE WS_CEP_EnderecoDasCoordenadas(LOCAL pLatitude is string, LOCAL pLongitude is string, LOCAL DebugSN)

IF GloDebugSN = "S" THEN
Info("WS_CEP_EnderecoDasCoordenadas")
DebugSN = "S"
END
//pLatitude= "-25.431637"
//plongitude ="-49.203203"
NextTitle("Atenção")

ok is boolean = False
GloEnderecoOK = False

Endereco, RetJson is string = ""
IF pLatitude <> 0 AND pLongitude <> 0 AND pLatitude <> Null AND pLongitude <> Null THEN

Url is string = "http://maps.googleapis.com/maps/api/geocode/json…=" + pLatitude + "," + pLongitude + "&sensor=true"

IF DebugSN = "S"
Info("01",Url)
END

HTTPTimeOut(GloHTTPTimeOut)


ok = HTTPRequest(Url)

IF ok = True THEN

ChangeCharset(charsetOccidental) // SEM ACENTO


RetJson = WS_Android_IOS_HTTPGetResult()//HTTPGetResult(httpResult)
IF Length(RetJson) = 0 THEN

ok= False
ELSE



IF DebugSN = "S"
Info(Url,RetJson)
END

// /// teste
// TagEndac is string
// io is int = PositionOccurrence(RetJson, TagEndac, firstRank, IgnoreCase )// + Length(TagEndac)
//
//
// TagEndac = Middle(retjson,PositionOccurrence(RetJson,"""address_components"" :", firstRank, IgnoreCase ),Length(RetJson))
// blocoJson is string = Middle( tagEndac,1,PositionOccurrence(TagEndac,"],", firstRank, IgnoreCase ))
// //<Result> = ExtractString(<Initial String> , <Rank> [, <Separator> [, <Browse Direction>]])
//
// if (blocoJson<> "") THEN
// Endereco = ExtractString(blocoJson,firstRank,"""types"" : [ ""street_number"" ]",FromEnd)
// END
//
// //Pega endereço (entre duas aspas)
// IF io> 0 THEN
// Endereco = ExtractString(RetJson[[io TO]],4,"""")
// GloEnderecoOK = True
//
// END
// //teste
//


TagEnd is string = """formatted_address"" :"
i is int = PositionOccurrence(RetJson, TagEnd, firstRank, IgnoreCase ) + Length(TagEnd)
Endereco =""
//Pega endereço (entre duas aspas)
IF i> 0 THEN
Endereco = ExtractString(RetJson[[i TO]],2,"""")
GloEnderecoOK = True

END

IF Endereco = "" OR RetJson = "ERRO" THEN
// busca por XML
GloEnderecoOK = False
Url = "http://maps.googleapis.com/maps/api/geocode/xml…=" + pLatitude + "," + pLongitude + "&sensor=true"

IF DebugSN = "S"
Info("02",Url)
END

HTTPTimeOut(GloHTTPTimeOut)

ok = HTTPRequest(Url)
IF ok = True THEN

RetXml is string = WS_Android_IOS_HTTPGetResult()// HTTPGetResult(httpResult)

IF Length(RetXml) = 0 THEN

ok= False
ELSE

IF DebugSN = "S"
Info("Xml:",RetXml)
END

//<formatted_address>Rua Professora Antonia Reginato Vianna, 442 - Capão da Imbuia, Cajuru, Curitiba - PR, 82810-300, Brasil</formatted_address>

IF PositionOccurrence(RetXml,"<formatted_address>",firstRank) > 0 THEN

//Endereço
nPosicaoInicial is int = PositionOccurrence(RetXml,"<formatted_address>",firstRank) + Length("<formatted_address>")
nPosicaoFinal is int = PositionOccurrence(RetXml,"</formatted_address>",firstRank) + Length("</formatted_address>")
nPosicaoFinal = nPosicaoFinal - nPosicaoInicial
Endereco = Middle(RetXml,nPosicaoInicial,nPosicaoFinal)
GloEnderecoOK = True

END
END
END
END
END
END

IF ok = False THEN
Popup(GloMsgSemInternet,"L")
END



Endereco = WS_RemoveAcentos(Endereco)

END





RESULT (Endereco)
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 12 décembre 2014 - 15:28
PROCEDURE WS_CEP_EnderecoRetornaLatLonGoogleMaps(LOCAL Endereco, LOCAL OrigemDestino, LOCAL DebugSN)

IF GloDebugSN = "S" THEN
Info("WS_CEP_EnderecoRetornaLatLonGoogleMaps")
DebugSN = "S"
END

ok is boolean = False

GloOutrasTelas = "S"

Retorno is string = ""

ChangeCharset(charsetOccidental) // SEM ACENTO


inicio, fim is int = 0

//Exemplo: http://maps.google.com/maps/api/geocode/json…

Endereco = NoAccent(Endereco)

Endereco = Replace(Endereco," ","+")

Endereco = "http://maps.google.com/maps/api/geocode/xml…"

HTTPTimeOut(GloHTTPTimeOut)

IF DebugSN = "S"
Info("Envio: "+Endereco)
END


ok = HTTPRequest(Endereco)


IF ok = True THEN

Retorno = HTTPGetResult(httpResult)

ChangeCharset(charsetOccidental) // SEM ACENTO

Retorno = Capitalize(WS_RemoveAcentos(Retorno))


Retorno = Replace(Retorno,"Matriz,","")

Retorno = Replace(Retorno,"Matriz","")

IF DebugSN = "S"
Info("Retorno: "+Retorno)
END

//Retorno da Consulta
IF DebugSN = "S" AND InSimulatorMode() = False THEN
IF InAndroidMode() = True
fSaveText("/mnt/sdcard/TaxiFv/Arquivos/WS_CEP_EnderecoRetornaLatLonGoogleMaps.txt",Retorno)
END
END

IF Retorno <> Null THEN


Retorno = Replace(Retorno,Charact(34),"")

//info(Return_Json)

//Retorno Esperado
//12345678901234567890
//lat : -25.4259127,
//lng : -49.249879

IF PositionOccurrence(Retorno,"OVER_QUERY_LIMIT",firstRank,FromBeginning) > 0 AND DebugSN = "S" THEN
NextTitle("Atenção")
Info("Excedeu a quantidade de pesquisas no google maps.")
ELSE

//Endereco
IF PositionOccurrence(Retorno,"<formatted_address>",firstRank,IgnoreCase) > 0 THEN
inicio = PositionOccurrence(Retorno,"<formatted_address>",firstRank,IgnoreCase) + 19
fim = PositionOccurrence(Retorno,"</formatted_address>",firstRank,IgnoreCase)

IF OrigemDestino = "O"
GloVoceEnderecoLongo = Middle(Retorno,inicio,fim-inicio)
ELSE IF OrigemDestino = "D"
GloDestinoEnderecoLongo = Middle(Retorno,inicio,fim-inicio)
END

END

//Latitude
IF PositionOccurrence(Retorno,"<lat>",firstRank,IgnoreCase) > 0 THEN
inicio = PositionOccurrence(Retorno,"<lat>",firstRank,IgnoreCase) + 5
fim = PositionOccurrence(Retorno,"</lat>",firstRank,IgnoreCase) - 1
GloLatitudeLocalizada = Val(Middle(Retorno,inicio,fim-inicio),"d")
IF OrigemDestino = "O"
GloVoceLatitude = GloLatitudeLocalizada
ELSE IF OrigemDestino = "D"
GloDestinoLatitude = GloLatitudeLocalizada
END
END

//Longitude
IF PositionOccurrence(Retorno,"<lng>",firstRank,IgnoreCase) > 0 THEN
inicio = PositionOccurrence(Retorno,"<lng>",firstRank,IgnoreCase) + 5
fim = PositionOccurrence(Retorno,"</lng>",firstRank,IgnoreCase) - 1
GloLongitudeLocalizada = Val(Middle(Retorno,inicio,fim-inicio),"d")
IF OrigemDestino = "O"
GloVoceLongitude = GloLongitudeLocalizada
ELSE IF OrigemDestino = "D"
GloDestinoLongitude = GloLongitudeLocalizada
END
END

//Retorno
IF OrigemDestino = "O" THEN
Retorno = GloVoceLatitude +";"+ GloVoceLongitude
ELSE IF OrigemDestino = "D"
Retorno = GloDestinoLatitude +";"+ GloDestinoLongitude
END

END


END



//Historico
// HReadSeekFirst(t008_inicial,t008_inicial.t008_codigo,1)
// IF HFound(t008_inicial) = True
// t008_inicial.t008_codigo = 1
// IF OrigemDestino = "O"
// t008_inicial.t008_endereco = GloVoceEnderecoLongo
// t008_inicial.t008_numero = 0
// t008_inicial.t008_latitude = GloVoceLatitude
// t008_inicial.t008_longitude= GloVoceLongitude
// else IF OrigemDestino = "D"
// t008_inicial.t008_endereco = GloBuscaEnderecoLongo
// t008_inicial.t008_numero = 0
// t008_inicial.t008_latitude = GloBuscaLatitude
// t008_inicial.t008_longitude= GloBuscaLongitude
// end
// HModify(t008_inicial)
// END


IF DebugSN = "S"
Info("Retorno", Retorno)
END

END

GloOutrasTelas = ""

RESULT(Retorno)
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 12 décembre 2014 - 15:29
PROCEDURE WS_CEP_LatLonRetornaEndereco(LOCAL Latitude, LOCAL Logitude, LOCAL OrigemDestino, LOCAL DebugSN)

IF GloDebugSN = "S" THEN
Info("WS_CEP_LatLonRetornaEndereco")
DebugSN = "S"
END

ok is boolean = False

GloOutrasTelas = "S"

Inicio , Final is int
Endereco is string = ""

IF Endereco = "Rua 1"
Endereco = "Rua Dr Goulin - 1661 - Centro - Curitiba - Parana - 82810-210 - Brasil"
END

//info("WS_CEP_LatLonRetornaEndereco")

ChangeCharset(charsetOccidental) // SEM ACENTO

ok = HExecuteQuery(QRY_T003GPS_Del)

//HTTPRequest("http://maps.googleapis.com/maps/api/geocode/json…")

HTTPTimeOut(GloHTTPTimeOut)


ok = HTTPRequest("http://maps.googleapis.com/maps/api/geocode/xml…")

Return_xml is string = HTTPGetResult(httpResult)

Return_xml = Replace(Return_xml,"Matriz,","")
Return_xml = Replace(Return_xml,"Matriz","")

//Pega o endereço

//<?xml version="1.0" encoding="UTF-8"?>
//<GeocodeResponse>
//<status>OK</status>
//<result>
//<type>street_address</type>
//12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
//<formatted_address>Rua Quinze de Novembro, 36-110 - Centro, Curitiba - PR, 80020-310, República Federativa do Brasil</formatted_address>
//<address_component>
//<long_name>36-110</long_name>
//<short_name>36-110</short_name>
//<type>street_number</type>
//</address_component>
//<address_component>
//<long_name>Rua Quinze de Novembro</long_name>
//<short_name>Rua 15 de Novembro</short_name>
//<type>route</type>
//</address_component>
//<address_component>
//<long_name>Centro</long_name>
//<short_name>Centro</short_name>
//<type>sublocality</type>
//<type>political</type>
//</address_component>
//<address_component>
//<long_name>Curitiba</long_name>
//<short_name>Curitiba</short_name>
//<type>locality</type>
//<type>political</type>
//</address_component>
//<address_component>
//<long_name>Paraná</long_name>
//<short_name>PR</short_name>
//<type>administrative_area_level_1</type>
//<type>political</type>
//</address_component>
//<address_component>
//<long_name>República Federativa do Brasil</long_name>
//<short_name>BR</short_name>
//<type>country</type>
//<type>political</type>
//</address_component>
//<address_component>
//<long_name>80020-310</long_name>
//<short_name>80020-310</short_name>
//<type>postal_code</type>
//</address_component>
//<geometry>
//<location>
//<lat>-25.4318564</lat>
//<lng>-49.2736597</lng>
//</location>
//<location_type>RANGE_INTERPOLATED</location_type>
//<viewport>
//<southwest>
//<lat>-25.4330753</lat>
//<lng>-49.2745276</lng>
//</southwest>
//<northeast>
//<lat>-25.4303773</lat>
//<lng>-49.2718296</lng>
//</northeast>
//</viewport>
//<bounds>
//<southwest>
//<lat>-25.4318813</lat>
//<lng>-49.2736836</lng>
//</southwest>
//<northeast>
//<lat>-25.4315713</lat>
//<lng>-49.2726736</lng>
//</northeast>
//</bounds>
//</geometry>
//</result>
//<result>


IF Return_xml <> "" AND Return_xml <> Null AND PositionOccurrence(Return_xml,"<status>ZERO_RESULTS</status>",firstRank,IgnoreCase) = 0 AND Length(Return_xml) > 120 THEN

IF PositionOccurrence(Return_xml, "<formatted_address>", firstRank, IgnoreCase ) > 0 THEN

//Retorno da Consulta
IF DebugSN = "S" AND InSimulatorMode() = False THEN
IF InAndroidMode() = True
fSaveText("/mnt/sdcard/TaxiFv/Arquivos/WS_CEP_LatLonRetornaEndereco.txt",Return_xml)
END
END

//formatted_address = endereco
Inicio = PositionOccurrence(Return_xml, "<formatted_address>", firstRank, IgnoreCase ) + 19
//geometry
Final = PositionOccurrence(Return_xml,"</formatted_address>", firstRank, IgnoreCase )
//Pega endereço
Endereco = Middle(Return_xml, Inicio, ((Final - Inicio)))
Endereco = Replace(Endereco,":","",IgnoreCase)
Endereco = Replace(Endereco,Charact(34),"",IgnoreCase)
Endereco = Replace(Endereco,"Brazil","Brasil",IgnoreCase)
t003_gps.EnderecoLongo003 = Capitalize(Endereco)
IF Endereco = "Olt County"
t003_gps.EnderecoLongo003 = ""
END
Return_xml = WS_ReplaceBoller(Return_xml,"</formatted_address>","</xxx>")
Return_xml = WS_ReplaceBoller(Return_xml,"</formatted_address>","</xxx>")


//Numero
// 12345678901234567890
//"<address_component>"+CR+"<long_name>"
Inicio = PositionOccurrence(Return_xml, "<long_name>", firstRank, IgnoreCase ) + 11
//geometry
Final = PositionOccurrence(Return_xml,"</long_name>", firstRank, IgnoreCase )
//Pega
t003_gps.Numero003 = Middle(Return_xml, Inicio, ((Final - Inicio)))
IF OrigemDestino = "O"
GloVoceNumero = t003_gps.Numero003
ELSE IF OrigemDestino = "D"
GloDestinoNumero = t003_gps.Numero003
END
Return_xml = WS_ReplaceBoller(Return_xml,"<long_name>","<xxx>")
Return_xml = WS_ReplaceBoller(Return_xml,"</long_name>","</xxx>")
Return_xml = WS_ReplaceBoller(Return_xml,"<short_name>","<xxx>")
Return_xml = WS_ReplaceBoller(Return_xml,"</short_name>","</xxx>")

//Endereco Curto
// 12345678901234567890
//"<address_component>"+CR+"<long_name>"
Inicio = PositionOccurrence(Return_xml, "<long_name>", firstRank, IgnoreCase ) + 11
//geometry
Final = PositionOccurrence(Return_xml,"</long_name>", firstRank, IgnoreCase )
//Pega
t003_gps.EnderecoCurto003 = Middle(Return_xml, Inicio, ((Final - Inicio)))
IF t003_gps.EnderecoCurto003 = "Olt County" THEN
t003_gps.EnderecoCurto003 = ""
END
t003_gps.EnderecoCurto003 = Capitalize(t003_gps.EnderecoCurto003)
Return_xml = WS_ReplaceBoller(Return_xml,"<long_name>","<xxx>")
Return_xml = WS_ReplaceBoller(Return_xml,"</long_name>","</xxx>")
Return_xml = WS_ReplaceBoller(Return_xml,"<short_name>","<xxx>")
Return_xml = WS_ReplaceBoller(Return_xml,"</short_name>","</xxx>")

//Bairro
// 12345678901234567890
//"<address_component>"+CR+"<long_name>"
Inicio = PositionOccurrence(Return_xml, "<long_name>", firstRank, IgnoreCase ) + 11
//geometry
Final = PositionOccurrence(Return_xml,"</long_name>", firstRank, IgnoreCase )
//Pega
t003_gps.Bairro003 = Middle(Return_xml, Inicio, ((Final - Inicio)))
Return_xml = WS_ReplaceBoller(Return_xml,"<long_name>","<xxx>")
Return_xml = WS_ReplaceBoller(Return_xml,"</long_name>","</xxx>")
Return_xml = WS_ReplaceBoller(Return_xml,"<short_name>","<xxx>")
Return_xml = WS_ReplaceBoller(Return_xml,"</short_name>","</xxx>")

//Cidade
// 12345678901234567890
//"<address_component>"+CR+"<long_name>"
Inicio = PositionOccurrence(Return_xml, "<long_name>", firstRank, IgnoreCase ) + 11
//geometry
Final = PositionOccurrence(Return_xml,"</long_name>", firstRank, IgnoreCase )
//Pega
t003_gps.Cidade003 = Middle(Return_xml, Inicio, ((Final - Inicio)))
//Bloco1
Return_xml = WS_ReplaceBoller(Return_xml,"<long_name>","<xxx>")
Return_xml = WS_ReplaceBoller(Return_xml,"</long_name>","</xxx>")

Return_xml = WS_ReplaceBoller(Return_xml,"<short_name>","<xxx>")
Return_xml = WS_ReplaceBoller(Return_xml,"</short_name>","</xxx>")

//Bloco2
Return_xml = WS_ReplaceBoller(Return_xml,"<long_name>","<xxx>")
Return_xml = WS_ReplaceBoller(Return_xml,"</long_name>","</xxx>")

Return_xml = WS_ReplaceBoller(Return_xml,"<short_name>","<xxx>")
Return_xml = WS_ReplaceBoller(Return_xml,"</short_name>","</xxx>")

//Estado
// 12345678901234567890
//"<address_component>"+CR+"<long_name>"
Inicio = PositionOccurrence(Return_xml, "<long_name>", firstRank, IgnoreCase ) + 11
//geometry
Final = PositionOccurrence(Return_xml,"</long_name>", firstRank, IgnoreCase )
//Pega
t003_gps.Estado003 = Middle(Return_xml, Inicio, ((Final - Inicio)))
Return_xml = WS_ReplaceBoller(Return_xml,"<long_name>","<xxx>")
Return_xml = WS_ReplaceBoller(Return_xml,"</long_name>","</xxx>")

//UF
// 12345678901234567890
//"<address_component>"+CR+"<long_name>"
Inicio = PositionOccurrence(Return_xml, "<short_name>", firstRank, IgnoreCase ) + 12
//geometry
Final = PositionOccurrence(Return_xml,"</short_name>", firstRank, IgnoreCase )
//Pega
t003_gps.UF003 = Middle(Return_xml, Inicio, ((Final - Inicio)))
IF t003_gps.UF003 = "CU" THEN
t003_gps.UF003 = "PR"
END

Return_xml = WS_ReplaceBoller(Return_xml,"<short_name>","<xxx>")
Return_xml = WS_ReplaceBoller(Return_xml,"</short_name>","</xxx>")

//Pais = Brasil
// 12345678901234567890
//"<address_component>"+CR+"<long_name>"
Inicio = PositionOccurrence(Return_xml, "<long_name>", firstRank, IgnoreCase ) + 11
//geometry
Final = PositionOccurrence(Return_xml,"</long_name>", firstRank, IgnoreCase )
//Pega
t003_gps.Pais003 = Middle(Return_xml, Inicio, ((Final - Inicio)))
Return_xml = WS_ReplaceBoller(Return_xml,"<long_name>","<xxx>")
Return_xml = WS_ReplaceBoller(Return_xml,"</long_name>","</xxx>")

//Pais curto
// 12345678901234567890
//"<address_component>"+CR+"<long_name>"
Inicio = PositionOccurrence(Return_xml, "<short_name>", firstRank, IgnoreCase ) + 12
//geometry
Final = PositionOccurrence(Return_xml,"</short_name>", firstRank, IgnoreCase )
//Pega
t003_gps.PaisCurto003 = Middle(Return_xml, Inicio, ((Final - Inicio)))
Return_xml = WS_ReplaceBoller(Return_xml,"<short_name>","<xxx>")
Return_xml = WS_ReplaceBoller(Return_xml,"</short_name>","</xxx>")

//CEP
// 12345678901234567890
//"<address_component>"+CR+"<long_name>"
Inicio = PositionOccurrence(Return_xml, "<long_name>", firstRank, IgnoreCase ) + 11
//geometry
Final = PositionOccurrence(Return_xml,"</long_name>", firstRank, IgnoreCase )
//Pega
t003_gps.CEP003 = Middle(Return_xml, Inicio, ((Final - Inicio)))
Return_xml = WS_ReplaceBoller(Return_xml,"<long_name>","<xxx>")
Return_xml = WS_ReplaceBoller(Return_xml,"</long_name>","</xxx>")
Return_xml = WS_ReplaceBoller(Return_xml,"<short_name>","<xxx>")
Return_xml = WS_ReplaceBoller(Return_xml,"</short_name>","</xxx>")


//Latitude
Inicio = PositionOccurrence(Return_xml, "<lat>", firstRank, IgnoreCase ) + 5
//geometry
Final = PositionOccurrence(Return_xml,"</lat>", firstRank, IgnoreCase ) - 1
//Pega
t003_gps.Latitude_A_003 = Middle(Return_xml, Inicio, ((Final - Inicio)))

//Longitude
Inicio = PositionOccurrence(Return_xml, "<lng>", firstRank, IgnoreCase ) + 5
//geometry
Final = PositionOccurrence(Return_xml,"</lng>", firstRank, IgnoreCase ) - 1
//Pega
t003_gps.Longitude_A_003 = Middle(Return_xml, Inicio, ((Final - Inicio)))

//Se tudo certo inclui na tabela
t003_gps.EnderecoLongo003 = Capitalize(WS_RemoveAcentos(t003_gps.EnderecoLongo003))

t003_gps.EnderecoCurto003 = Capitalize( WS_RemoveAcentos(t003_gps.EnderecoCurto003))

t003_gps.OrigemDestino = OrigemDestino

IF t003_gps.EnderecoCurto003 <> "" AND t003_gps.EnderecoLongo003 <> ""
HAdd(t003_gps)
END

ELSE
Endereco = ""
END

END

//Resultado

IF Endereco <> Null
Endereco = Capitalize(Endereco)
END

FOR EACH t003_gps

IF DebugSN = "S"
Info(t003_gps.EnderecoCurto003,t003_gps.Numero003, t003_gps.Bairro003, t003_gps.Cidade003, t003_gps.Estado003, t003_gps.UF003, t003_gps.Pais003, t003_gps.PaisCurto003, t003_gps.CEP003, t003_gps.Latitude_A_003,t003_gps.Longitude_A_003)
END

IF t003_gps.OrigemDestino = "O" THEN

GloVoceEnderecoLongo = t003_gps.EnderecoLongo003
GloVoceEndereco = t003_gps.EnderecoCurto003
GloVoceNumero = t003_gps.Numero003
GloVoceLatitude = t003_gps.Latitude_A_003
GloVoceLongitude = t003_gps.Longitude_A_003
GloVoceCidade = t003_gps.Cidade003
GloVoceUf = t003_gps.UF003

WS_RetornoOrigem()

ELSE IF t003_gps.OrigemDestino = "D" THEN

GloDestinoEnderecoLongo= t003_gps.EnderecoLongo003
GloDestinoEndereco = t003_gps.EnderecoCurto003
GloDestinoNumero = t003_gps.Numero003
GloDestinoLatitude = t003_gps.Latitude_A_003
GloDestinoLongitude = t003_gps.Longitude_A_003
GloDestinoCidade = t003_gps.Cidade003
GloDestinoUf = t003_gps.UF003

WS_RetornoDestino()

END
END

//Historico
//HReadSeekFirst(t008_inicial,t008_inicial.t008_codigo,1)
//IF HFound(t008_inicial) = True
// t008_inicial.t008_codigo = 1
// IF OrigemDestino = "O"
// t008_inicial.t008_endereco = GloVoceEnderecoLongo
// t008_inicial.t008_numero = 0
// t008_inicial.t008_latitude = GloVoceLatitude
// t008_inicial.t008_longitude= GloVoceLongitude
// ELSE IF OrigemDestino = "D"
// t008_inicial.t008_endereco = GloBuscaEnderecoLongo
// t008_inicial.t008_numero = 0
// t008_inicial.t008_latitude = GloBuscaLatitude
// t008_inicial.t008_longitude= GloBuscaLongitude
// END
// HModify(t008_inicial)
//END


IF Endereco = "Rua 1"
Endereco = "Rua Dr Goulin - 1661 - Centro - Curitiba - Parana - 82810-210 - Brasil"
END

GloOutrasTelas = ""

RESULT(Endereco)
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 08 juin 2016 - 01:35
Exemplo de Serialize

http://help.windev.com/en-US/…

// Structure to transform into JSON
ST_Product is structure
// <Serialize> allows you to have a different name in JSON
sName is string <Serialize ="ProductName">
nID is int
nQty is int
mValue is currency <Serialize ="Amount">
END
ST_Person is structure
sLastName is string <Serialize ="LastName">
sFirstName is string <Serialize ="FirstName">
dDOB is Date
arrProducts is array of ST_Product
END
arrPersons is array of ST_Person

// Fill the data
nPersonSubscript is int
nProductSubscript is int
nPersonSubscript = ArrayAdd(arrPersons)
arrPersons[nPersonSubscript].sLastName = "Doe"
arrPersons[nPersonSubscript].sFirstName = "John"
arrPersons[nPersonSubscript].dDOB = "19880516"

nProductSubscript = ArrayAdd(arrPersons[mPersonSubscript].arrProducts)
arrPersons[nPersonSubscript].arrProducts[nProductSubscript].mValue = 89.9
arrPersons[nPersonSubscript].arrProducts[nProductSubscript].nID = 12345724
arrPersons[nPersonSubscript].arrProducts[nProductSubscript].nQty = 5
arrPersons[nPersonSubscript].arrProducts[nProductSubscript].sName = "Red jacket"

// Retrieve the JSON code
bufJson is Buffer
Serialize(arrPersons.bufJson, psdJSON
//[ {
// "LastName":"Doe",
// "FirstName":"John",
// "dDOB":"1988-05-16",
// "arrProducts":[ {
// "ProductName":"Red jacket",
// "nID":12345724,
// "nQty":5,
// "Amount":89.9
// } ]
// } ]

// Send the JSON to a site by POST
HTTPCreateForm("JSONForm")
HTTPAddParameter("JSONForm", "JSONPERSON", bufJson)
HTTPSendForm("JSONForm", ...
"http://MySite/MySite_WEB/US/PAGE_Persons.awp", httpPost)




Exemplo de Deserialize

http://help.windev.com/en-US/…

// This example explains how to use the Serialize/Deserialize functions
// with an Array variable.
// These functions can use all types of WLanguage variables.


MyArray is array of strings
bufResult is Buffer

// Adds elements into the array
Add(MyArray, "WINDEV")
Add(MyArray, "WEBDEV")
Add(MyArray, "WINDEV MOBILE")

// Serialize the array in the buffer in JSON
// => Save the array and its entire content in a JSON string
Serialize(MyArray, bufResult, psdJSON)

// Deserialize the JSON buffer
// => Rebuild the WLanguage array from the JSON string
MyRebuiltArray is array of strings
Deserialize(MyRebuiltArray, bufResult, psdJSON)





Exemplo de Structure

http://help.windev.com/en-US/…

// Declare a structure
ProductRef is structure
SCode is int
PdtCode is fixed string on 10
END

// Declare a structure variable
ProductRef is structure
SCode is int
PdtCode is fixed string on 10
END

Armchair is ProductRef

// Handle a member of a structure variable
ProductRef is structure
SCode is int
PdtCode is fixed string on 10
END

Armchair is ProductRef
Armchair:SCode = 7
Armchair:PdtCode = "Furniture"


--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 9949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 26 juillet 2016 - 00:27
REQUISITOS BÁSICOS PARA UM WEBSERVICE SOAP OU REST:

- Instalar e Configurar o IIS ou Apache

- Instalar e configurar o WAS reserved ou a versão FULL

- Configurar o Firewall

- Configurar o antivírus para aceitar os programas e drivers em execução como seguros

- Verificar as portas se nao estao sendo usadas por outros programas

- Instalar o banco de dados exemplo hfsql ou mysql... (mssqlserver, oracle, db2, as/400 sao drivers nativos pagos)

- Instalar o gerenciador de banco de dados SGDB, Center Hfsql ou phpmyadmin, workbank...

- Instalar o Driver Nativo, exemplo MySql da pcsoft

- Instalar o Noip ou contratar um IP Fixo ou um host server Windows ou Linux com acesso as configurações e execução de comandos e deixar o WAS rodando

- roteador da internet, criar o alias da porta :8081 para quando usar o endereço dns do seu noip ou do seu ip fixo seja roteado para o seu servidor no ip da classe C tipo 192.168.1.100 e o IIS ou Apache abra a sua página ou o seu webservice SOAP ou REST de qualquer lugar do planeta.

--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 9949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/