Article From:https://segmentfault.com/q/1010000011111853
Question:

This is my code

if __name__ == "__main__":
    clearLogConfig = os.getenv("CLEAR_LOG_CONFIG")
    print clearLogConfig
    clearLogConfig = json.loads(clearLogConfig)
    print clearLogConfig
    exit()

The manual test is also OK

Answer 0:

You have to stick it upclearLogConfigWhat is this? Is it a string that satisfies the JSON format?

import json, os
clearLogConfig = os.getenv("CLEAR_LOG_CONFIG", '{"a": 1}')
print (clearLogConfig)
clearLogConfig = json.loads(clearLogConfig)
print (clearLogConfig)

With the addition of single quotes, the following code will report errors:

import json
a = "'{'a':1}'"
a = json.loads(a)

Answer 1:

CLEAR_LOG_CONFIGWhat is the value? This value must be in accordance with the JSON specification.
https://github.com/darcyliu/g…

Answer 2:

Look at your code, it should beclearLogConfigThe value of the variable is not a standard JSON string. You can try the following code:

if __name__ == "__main__":
    clearLogConfig = os.getenv("CLEAR_LOG_CONFIG")
    clearLogConfig = clearLogConfig[1:-1]
    print clearLogConfig
    clearLogConfig = json.loads(clearLogConfig)
    print clearLogConfig
    exit()

Leave a Reply

Your email address will not be published. Required fields are marked *