In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
Today, I would like to share with you how to use Python to read json files related to knowledge, detailed content, clear logic, I believe that most people are too aware of this knowledge, so share this article for your reference, I hope you will learn something after reading this article, let's take a look at it.
JSON (JavaScript Object Notation) is a lightweight data exchange format. It is based on a subset of ECMAScript. JSON uses a completely language-independent text format, but also uses conventions similar to the C language family (including C, C++, Java, JavaScript, Perl, Python, and so on). These features make JSON an ideal data exchange language. It is easy for people to read and write, and it is also easy to be parsed and generated by machines (generally used to increase the network transmission rate).
JSON is composed of list and dict in python.
These are two modules for serialization:
Json: used for converting between string and python data types pickle: for converting between python-specific types and python data types
The Json module provides four functions:
Dumps 、 dump 、 loads 、 load
The pickle module provides four functions:
Dumps 、 dump 、 loads 、 load
Json dumps converts data types to strings dump converts data types to strings and stores them in files loads converts strings to data types load converts files from strings to data types.
Json can exchange data between different languages, while pickle is only used between python. Json can only serialize the most basic data types, and josn can only serialize common data types (lists, dictionaries, lists, strings, numbers, etc.), such as date formats, class objects! Josn can't. Pickle can serialize all data types, including classes, and functions can be serialized.
Example
Dumps: converts dictionaries in python to strings
Import jsontest_dict = {'bigberg': [7600, {1: [[' iPhone', 6300], ['Bike', 6300]]}} print (test_dict) print (type (test_dict)) # dumps converts the data into a string json_str = json.dumps (test_dict) print (json_str) print (type (json_str))
Loads: convert strings to dictionaries
1 new_dict = json.loads (json_str) 2 print (new_dict) 3 print (type (new_dict)) above is all the content of the article "how to read json files with Python". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.