I have a text file like this :
"imei": "123456789", "sim_no": "+90 xxx xxx xx xx", "device_type": "standart", "hw_version": "1.01", "sw_version": "1.02"
and i want to convert to dictionary this file. Because i want to take values.
import json
from time import sleep
def buffer(data):
dicto=json.loads(data)
print(type(dicto))
file=open("config.txt", "r").read()
jsondata=json.dumps(file)
buffer(jsondata)
result : <class 'str'>
When i working in shell like this :
>>> import json
>>> h = '{"foo":"bar", "foo2":"bar2"}'
>>> type(h)
<class 'str'>
>>> d=json.loads(h)
>>> d
{'foo2': 'bar2', 'foo': 'bar'}
>>> type(d)
<class 'dict'>
>>>
its working but i can't understand why my code not working. When i convert this file to dictionary i want to hold in a buffer. How can i hold this data inside array? Please excuse me i am new in Python.
config.txtfile?json.loads?