Im getting this response from Google (UNICODE)

Just starting out? Need help? Post your questions and find answers here.
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Im getting this response from Google (UNICODE)

Post by ricardo »

Code: Select all

StatusCode: 200
Response: ["what does it means to dreams with zombies",[["what does it\u003cb\u003e mean \u003c\/b\u003eto\u003cb\u003e dream \u003c\/b\u003ewith zombies",0,[22,30]]],{"i":"what does it means to dreams with zombies","q":"NrG4vjGNoVAQjCl6p-9df7Lg96A","t":{"bpc":false,"tlw":false}}]
I tried to make my ee UNICODE and does not work.
How can i read this result? Im not running an html page. Just getting this text and want to be able to read it right

Best Regards
ARGENTINA WORLD CHAMPION
BarryG
Addict
Addict
Posts: 4122
Joined: Thu Apr 18, 2019 8:17 am

Re: Im getting this response from Google (UNICODE)

Post by BarryG »

Wouldn't you just read the first part and ignore the rest since it's just duplicate data?
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Im getting this response from Google (UNICODE)

Post by ricardo »

BarryG wrote: Sun Apr 16, 2023 2:46 am Wouldn't you just read the first part and ignore the rest since it's just duplicate data?
Per exmaple, firts answer: "what does it\u003cb\u003e mean \u003c\/b\u003eto\u003cb\u003e dream \u003c\/b\u003ewith zombies",


It means: What does it mean to dream with zombies"

Maybe i just have to ignore and delete \u003cb \u003e \u003c\ /b\u003e ?
ARGENTINA WORLD CHAMPION
BarryG
Addict
Addict
Posts: 4122
Joined: Thu Apr 18, 2019 8:17 am

Re: Im getting this response from Google (UNICODE)

Post by BarryG »

You missed my point. Why bother trying to decode this:

"what does it\u003cb\u003e mean \u003c\/b\u003eto\u003cb\u003e dream \u003c\/b\u003ewith zombies"

When it's already there at the start of the string like this:

"what does it means to dreams with zombies"

It's the exact same text without any decoding needed.
infratec
Always Here
Always Here
Posts: 7576
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Im getting this response from Google (UNICODE)

Post by infratec »

You have to search for \u and then use the next 4 characters and Chr($....)

Code: Select all

Procedure.s UnicodeDecode(String$)
  
  Protected Encoded$
  
  Pos = FindString(String$, "\u")
  While Pos
    Encoded$ = Mid(String$, Pos + 2, 4)
    String$ = ReplaceString(String$, "\u" + Encoded$, Chr(Val("$" + Encoded$)))
    Pos = FindString(String$, "\u")
  Wend
  
  ProcedureReturn String$
  
EndProcedure
Last edited by infratec on Sun Apr 16, 2023 10:15 am, edited 1 time in total.
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Im getting this response from Google (UNICODE)

Post by Lunasole »

I've recently found one interesting solution :?:

Code: Select all

Debug Google / 0.0
But you see, what @Ifratec posted is more useful in this case.
By fact just escaped unicode chars inside json, PB probably still has no own functions to unescape something like this, so can use something own or external.
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: Im getting this response from Google (UNICODE)

Post by jassing »

How's this?

Code: Select all

CreateRegularExpression(0,"(\\u[0-9]{3}(cb|c|e)|\\/b)")
text.s = "what does it\u003cb\u003e mean \u003c\/b\u003eto\u003cb\u003e dream \u003c\/b\u003ewith zombies"
Debug ReplaceRegularExpression(0,text,"")
or more simply:

Code: Select all

CreateRegularExpression(0,"(\\u003(cb|c|e)|\\/b)")
text.s = "what does it\u003cb\u003e mean \u003c\/b\u003eto\u003cb\u003e dream \u003c\/b\u003ewith zombies"
Debug ReplaceRegularExpression(0,text,"")
I don't know all the details of what possible encoding there is...
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Im getting this response from Google (UNICODE)

Post by Lunasole »

jassing wrote: Sun Apr 16, 2023 1:45 pm How's this?

Code: Select all

CreateRegularExpression(0,"(\\u[0-9]{3}(cb|c|e)|\\/b)")
text.s = "what does it\u003cb\u003e mean \u003c\/b\u003eto\u003cb\u003e dream \u003c\/b\u003ewith zombies"
Debug ReplaceRegularExpression(0,text,"")
or more simply:

Code: Select all

CreateRegularExpression(0,"(\\u003(cb|c|e)|\\/b)")
text.s = "what does it\u003cb\u003e mean \u003c\/b\u003eto\u003cb\u003e dream \u003c\/b\u003ewith zombies"
Debug ReplaceRegularExpression(0,text,"")
I don't know all the details of what possible encoding there is...
Nice regexp variants too, at least if really make it for all chars range.
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: Im getting this response from Google (UNICODE)

Post by jassing »

Lunasole wrote: Sun Apr 16, 2023 4:52 pm Nice regexp variants too, at least if really make it for all chars range.
I did a very quick google search and didn't find a good reference to all encoding sequences, so I just used what was there & guessed... (hence the 1st 'any digit' variant) My 1st stab was too generic and engulfed the 'with' (\u003c\/b\u003ewith) too; so there must be a static format/valid characters, otherwise the encoding is pointless.

Even very complex regular expressions can be very fast. For things like this, I find it worthwhile, if not for the simplicity in code... (3 lines vs a 20 line procedure....)
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Im getting this response from Google (UNICODE)

Post by ricardo »

BarryG wrote: Sun Apr 16, 2023 3:49 am You missed my point. Why bother trying to decode this:

"what does it\u003cb\u003e mean \u003c\/b\u003eto\u003cb\u003e dream \u003c\/b\u003ewith zombies"

When it's already there at the start of the string like this:

"what does it means to dreams with zombies"

It's the exact same text without any decoding needed.

No, but the whole Google text have more than just the one that is already there. It has 5 or more strings, all with this things between wrods, and i need to clean it or understand how this works.

This is per example the whole Google answer:
["what does it means to dreams with zombies",[["what does it\u003cb\u003e mean \u003c\/b\u003eto\u003cb\u003e dream \u003c\/b\u003ewith zombies",0,[22,30]],["what does it\u003cb\u003e mean when you see \u003c\/b\u003ezombies\u003cb\u003e in your \u003c\/b\u003edreams",0,[650,390]]],{"i":"what does it means to dreams with zombies","q":"TK80Vzv2ltsd0SF7b80QZBnZ5yE","t":{"bpc":false,"tlw":false}}]
ARGENTINA WORLD CHAMPION
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: Im getting this response from Google (UNICODE)

Post by jassing »

ricardo wrote: Sun Apr 16, 2023 7:51 pm i need to clean it or understand how this works.
the regex solution didn't work for you?
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Im getting this response from Google (UNICODE)

Post by Lunasole »

"what does it means to dreams with zombies"

This is itself an interesting query, of what have you formed it?
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Im getting this response from Google (UNICODE)

Post by Lunasole »

Lunasole wrote: Tue Apr 25, 2023 12:04 am "what does it means to dreams with zombies"

This is itself an interesting query, of what have you formed it?
I'd also answer to it like: just great, nothing will break nor freedom or truth.
You may repeat such loops infinitely, that won't change. At some moment I'd break that anyway and just die, because maybe will have no more powers to redirect own life to some other way.
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Im getting this response from Google (UNICODE)

Post by Lunasole »

And yes, you anyway have a lot to pay for me, and that's not about paying something like punishment^^
+1, I even don't need to count your loops and my responses. And more of it, I'm evolving even of that.
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
NicTheQuick
Addict
Addict
Posts: 1503
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Im getting this response from Google (UNICODE)

Post by NicTheQuick »

That's just JSON. Decode it properly with the JSON functions of Purebasic and the string will be decoded correctly.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Post Reply