json.load()和json.loads()函数有什么区别 [英] What is the difference between json.load() and json.loads() functions
问题描述
在Python中,json.load()
和json.loads()
有什么区别?
In Python, what is the difference between json.load()
and json.loads()
?
我猜想 load()函数必须与文件对象一起使用(因此,我需要使用上下文管理器),而 loads()函数采用文件的路径(字符串).这有点令人困惑.
I guess that the load() function must be used with a file object (I need thus to use a context manager) while the loads() function take the path to the file as a string. It is a bit confusing.
json.loads()
中的字母" s "代表字符串吗?
Does the letter "s" in json.loads()
stand for string?
非常感谢您的回答!
推荐答案
是的,s
代表字符串. json.loads
函数不采用文件路径,而是将文件内容作为字符串.在 https://docs.python.org/2/library/json中查看文档. html !
Yes, s
stands for string. The json.loads
function does not take the file path, but the file contents as a string. Look at the documentation at https://docs.python.org/2/library/json.html!
这篇关于json.load()和json.loads()函数有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!