python中的json注意事项
发布日期:2021-05-06 21:42:28 浏览次数:14 分类:原创文章

本文共 656 字,大约阅读时间需要 2 分钟。

案例一、正常输出情况

import json

jsonData = '{"a":1,"b":2,"c":1.2,"d":true,"e":null,"e":null}';

text = json.loads(jsonData)

text

输出

{'a': 1, 'b': 2, 'c': 1.2, 'd': True, 'e': None, 'f': None}

 

案例二、json中的引号变成单引号

 File "<ipython-input-71-9db4caf88c5e>", line 3
    jsonData = '{"a":1,"b":2,"c":1.2,"d":true,"e":null,'f':null}';
              ^
SyntaxError: f-string: single '}' is not allowed

 

案例三、布尔值变成大写开头会怎么样呢,即python中的规范

import json

jsonData = '{"a":1,"b":2,"c":1.2,"d":True,"e":null,"f":null}';

text = json.loads(jsonData)

text

输出错误

 

案例四、null中替换成None,可不可以呢,python中对None的定义

import json

jsonData = '{"a":1,"b":2,"c":1.2,"d":true,"e":None,"f":null}';

text = json.loads(jsonData)

text

输出错误

 

上一篇:para1、para2与**kw
下一篇:类不能直接通过import得到

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2025年03月14日 17时04分10秒