Read JSON formatted string in Python

后端 未结 4 1763
旧时难觅i
旧时难觅i 2021-01-23 00:15

I have a simple Websockets server in python, it receives messages from Android app clients, I tried to make the message payload from the client in JSON but I felt. It is only wo

4条回答
  •  忘掉有多难
    2021-01-23 00:35

    Will something like this work for you?

    import json
    
    # assume this is the JSON you receive
    text = json.dumps(dict(name='Jack', age='24'))
    
    # show the text to be converted
    print(text)
    # outputs: {"name": "Jack", "age": "24"}
    
    # load a string and convert to Python object
    # see `json` module more for details
    obj = json.loads(text) 
    

提交回复
热议问题