Android Question JSON parser

Hey
I faced such a problem, I will be glad to any advice or help, perhaps someone has already encountered such a problem. I store my data encoded as strings (locally and on a remote server, like base64). Now, when I receive a JSON file, I get an error because the string that I need to decode has too many characters as "", and the decoding turns out garbage that cannot be parsed in any way, what should I do in this case?

for example:
encoded output from server: akLlM81Fmc2Rnmc2Q
decoded this string: [{"key1":"value"}] etc.
On this moment i have error, because my decoding function return garbage because of this characters -> " "

Decoding sub works correctly

best regards
 
after many attempts I figured out that the $$ symbol should be used, like $"key":"value"$

but how to convert a string from base64 if it produces quotes when decoded

I have this code
B4X:
dim decodedString as string = B64.DecodeStoS($"${codesb}"$, "UTF8")

where codesb includes my encoded string
 
Upvote 0
I don't understand what you are doing but it looks completely wrong.

You should use the JSON library to parse or generate json strings.

hello, Erel, thanks for the answer.
I receive the JSON file from the server encrypted, it is contained in the variable codesb. I'm trying to encode this character set and write the result to a variable decodedString. And return this variable for the JSON parser. But when i decode it breaks because of the quotes
 
Upvote 0
This is not a valid json string. You should post more information...

its decoding result after
B4X:
dim decodedString as string = B64.DecodeStoS($"${codesb}"$, "UTF8")


but it should be something like this
[{"id":"473","Finished":"0"},{"id":"494","Finished":"0"},{"id":"495","Finished":"0"}]
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Your code is the same as:
B4X:
dim decodedString as string = B64.DecodeStoS(codesb , "UTF8")
2. It returns the base64 decoding. There is a problem somewhere but it is not in the base64 decoding. Maybe in the server.
You can test it with this tool: https://www.base64decode.org/
 
Upvote 0
1. Your code is the same as:
B4X:
dim decodedString as string = B64.DecodeStoS(codesb , "UTF8")
2. It returns the base64 decoding. There is a problem somewhere but it is not in the base64 decoding. Maybe in the server.
You can test it with this tool: https://www.base64decode.org/


It is unlikely that the problem is in the server. When I feed the decrypted values straight, everything works, but when I try to decrypt the value from the server into a string, I run into a problem with quotes, the string doesn't know where it ends. Something like this

I have this Result from server: -> iamWQiiIj0ziLC1JwYWlX3VwIjoiMCJ9LHsiaWiO

While decoding my string look like [{ Qd":$�73"/�pa_|��:"0"[��쉥���"��Ј���&�E�W#�!L�KȖB#���
I try return this value for the JSON parser, but it should looks like: [{"id":"473","Finished":"0"},{"id":"494","Finished":"0"},{"id":"495","Finished":"0"}]

when i decoding it from my PHP function it works
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
So what does this give you in your logs???
B4X:
    Dim SU As StringUtils
    Log(SU.DecodeBase64(codesb))

Would you mind posting the actual full encrypted value in your next response???
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
but when I try to decrypt the value from the server into a string
How are you decrypting the value? Looks like there may be an issue with the decryption
 
Upvote 0

emexes

Expert
Licensed User
after many attempts I figured out that the $$ symbol should be used, like $"key":"value"$

Why do you have:
B4X:
dim decodedString as string = B64.DecodeStoS($"${codesb}"$, "UTF8")
and not just:
B4X:
dim decodedString as string = B64.DecodeStoS(codesb, "UTF8")
.
If codesb is truly Base64, then it should have only ASCII characters < CHR(127) and "UTF8" should work just fine (as would most other maps too).

But you seem to be getting a lot of UTF decoding error flags "�" which makes me wonder what codesb is *before* it is run through DecodeStoS().
 
Upvote 0
Top