[英]What is the type of a JSON object in python?
I'm new to JSON. 我是JSON的新手。 I have a dictionary, I convert it to a JSON object using 我有一个字典,我使用它将其转换为JSON对象
myJsonObject = json.dumps(myDictionary)
But then If I check the type, I get <type 'str'>
但是如果我检查类型,我会得到<type 'str'>
Is string is the expected output for a JSON object? 字符串是JSON对象的预期输出吗?
PS: Python 2.7 PS:Python 2.7
Update: How can I get a JSON type, if dumps is not the correct way? 更新:如果转储不正确,我怎样才能获得JSON类型?
Of course, this is called "Serialization" - you are dumping a Python data structure into a JSON formatted string : 当然,这称为“序列化” - 您将Python数据结构转储为JSON格式的字符串 :
json.dumps()
Serialize obj to a JSON formatted str using this conversion table . 使用此转换表将 obj序列化为JSON格式的str。
If you load a JSON string with loads()
, this would be "deserialization" and you would get a Python list or a dictionary. 如果你使用loads()
加载一个JSON字符串,这将是“反序列化”,你会得到一个Python列表或字典。
The N of JSON is for Notation ; JSON的N用于表示法; it is, indeed, a data format specification. 实际上,它是一种数据格式规范。 A JSON object is usually intended to be used as a storage or inter-process communication format. JSON对象通常用作存储或进程间通信格式。 That's why it is in Python the universal flat format accepted by write() : a string object. 这就是为什么它在Python中是write()接受的通用平面格式:一个字符串对象。
You can print it to screen, save it to a file, or communicate it to another program to verify it is correct and containing expected data. 您可以将其打印到屏幕,将其保存到文件,或将其传送到另一个程序以验证它是否正确并包含预期数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.