JSON Decoder issue - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: JSON Decoder issue (/thread-4919.html) |
JSON Decoder issue - Cronax3 - Sep-13-2017 Hey community, currently I am programming a programing which is using the python Bittrex-API wrapper. I ran into a problem which I am not able to resolve at the moment so I am asking for some help. I am receiving a current market json file and a pretty confusing error. As you can see having a look at the ouput I first print out the receiving data from the API wrapper but JSON is complaingin as you can see at the bottom. I dunno how to fix this :( Sourcecode: from bittrex import Bittrex import json my_bittrex = Bittrex(None, None) buffer = str(my_bittrex.get_ticker("USDT-BTC")).replace("'",'"') print(buffer) parsed_json = json.loads(buffer) print(parsed_json["Last"])Just in case you are wondering about the replace function: I used it because the API wrapper returns a json string using single quotes and JSON complained about it. It said I have to use double quotes so I replaced them. Output:
RE: JSON Decoder issue - nilamo - Sep-13-2017 Quote:buffer = str(my_bittrex.get_ticker("USDT-BTC")).replace("'",'"') ^^^ What type is it before you turn it into a string? RE: JSON Decoder issue - Cronax3 - Sep-13-2017 The Datatype is 'dict'. Ok as I realize now I don't need to tread it as a json. Its not meant to be json at all and thats why the decoder is complaining. I misunderstood the api documentation. I completely messed this point up. Didn't even realize its a dict. My problem is solved now. Thanks for the hint! |