json.load() 和 json.loads() 函数有什么区别 [英] What is the difference between json.load() and json.loads() functions

查看:38
本文介绍了json.load() 和 json.loads() 函数有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 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"是否代表string?

Does the letter "s" in json.loads() stand for string?

非常感谢您的回答!

推荐答案

是的,s 代表字符串.json.loads 函数不取文件路径,而是取文件内容作为字符串.查看文档.

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.

这篇关于json.load() 和 json.loads() 函数有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆