PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV Mobile 2024 → Json To Ansi
Json To Ansi
Débuté par adrianoboller, 18 nov. 2014 13:44 - Aucune réponse
Membre enregistré
3 661 messages
Popularité : +175 (223 votes)
Posté le 18 novembre 2014 - 13:44
// 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