pogodevorg/pgoapi

valid JSON

Closed this issue · 6 comments

Im guessing you're just outputting what you're getting from the server. Right now we're getting single quotes back instead of double quotes, also True instead of "true" or 1, etc, both I did some string replace, but the last one that just popped up is this one:

"active_fort_modifier": b "9QM=",

Im not even sure how to replace that one especially if the value changes.

If this is my problem then please let me know. Or if there is a way around it, etc if this question is marked as incompetent as Ive seen others then please tell me why and feel free to delete :)

And thanks again you guys, following the discord from when it started.. I was constantly awed by you guys working :)

JSON.dumps() is what you need

Ok thank you Im experimenting with that and it looks like that line I mentioned previously is causing problems:

TypeError: b'9QM=' is not JSON serializable

b'9QM=' is a bytes object, decode it to a str object first for json.dumps to work - i.e. b'9QM='.decode('utf-8')

Ah ok thanks so Im working from the pokecli.py file

response_dict = api.get_map_objects(latitude =position[0], longitude = position[1], since_timestamp_ms = timestamps, cell_id = cell_ids)

to display it, it has

print('{}'.format(pprint.PrettyPrinter(indent=4).pformat(response_dict)))

I changed it to

print(json.dumps(response_dict))

after I did an include json at the top of the file. Im not a python guy, (Im PHP) so what I am doing at best, is hacking this file. I could potentially do a response_dict.decode('utf-8') but when I tried that (ok yes, I can tell that you're laughing now :) or shaking your head, or.. something :))

So I don't see anything in this file that allows me to modify the individual resulting values... before I encode into JSON.

Also it sounds like I might be having a problem with the pokecli.py file, not necessarily the library, which then that means this isn't an issue, but more of a "need help" type thing instead.. if that's the case, where would be a good place to get help so that I do not add chatter to the "issues" if this isn't an actual "issue" with the library?

Definitely not an issue; could seek help in the Discord chat.

Anyhow - without going in to too much support - if you are trying to get a JSON representation of the Dictionary object, then you could do json.dumps(response_dict, ensure_ascii=False) as long as you don't care about unprintable characters.

Thank you @elliotcarlson, and thanks @globeriz for the incompetence ;)