Page 1 of 1

Im getting this response from Google (UNICODE)

Posted: Sun Apr 16, 2023 2:44 am
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

Re: Im getting this response from Google (UNICODE)

Posted: Sun Apr 16, 2023 2:46 am
by BarryG
Wouldn't you just read the first part and ignore the rest since it's just duplicate data?

Re: Im getting this response from Google (UNICODE)

Posted: Sun Apr 16, 2023 3:37 am
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 ?

Re: Im getting this response from Google (UNICODE)

Posted: Sun Apr 16, 2023 3:49 am
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.

Re: Im getting this response from Google (UNICODE)

Posted: Sun Apr 16, 2023 9:00 am
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

Re: Im getting this response from Google (UNICODE)

Posted: Sun Apr 16, 2023 9:51 am
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.

Re: Im getting this response from Google (UNICODE)

Posted: Sun Apr 16, 2023 1:45 pm
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...

Re: Im getting this response from Google (UNICODE)

Posted: Sun Apr 16, 2023 4:52 pm
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.

Re: Im getting this response from Google (UNICODE)

Posted: Sun Apr 16, 2023 5:39 pm
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....)

Re: Im getting this response from Google (UNICODE)

Posted: Sun Apr 16, 2023 7:51 pm
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}}]

Re: Im getting this response from Google (UNICODE)

Posted: Sun Apr 16, 2023 9:41 pm
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?

Re: Im getting this response from Google (UNICODE)

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

This is itself an interesting query, of what have you formed it?

Re: Im getting this response from Google (UNICODE)

Posted: Tue Apr 25, 2023 11:25 pm
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.

Re: Im getting this response from Google (UNICODE)

Posted: Tue Apr 25, 2023 11:27 pm
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.

Re: Im getting this response from Google (UNICODE)

Posted: Tue Apr 25, 2023 11:48 pm
by NicTheQuick
That's just JSON. Decode it properly with the JSON functions of Purebasic and the string will be decoded correctly.