I use the pyserial library to get data from an Arduino. I use the fallowing code:
import serial
import JSON
ser = serial.Serial('/dev/ttyUSB0', 9600)
while True:
print(ser.readline())
When I run the program I get: b'{"x":"-1","y":"0"}\r\n'
but I expect {"x":"-1","y":"0"}
.
I know that I can remove \r\n by using stipe() method on ser,redline(). I also noticed that b' is from bytes.
When I try load string to json by command data = json.load(ser.readline().strip())
I get an error AttributeError: 'bytes' object has no attribute 'read'
How can I parse the string to json format?