The use of JSON modules for Python interface testing

Source: Internet
Author: User

    1. Json.dumps ()
    2. Json.loads ()
    3. Json.dump
    4. Json.load

First, Json.dumps ()

Convert a Python dictionary type to a JSON object

Import json# Python dictionary type converted to JSON object data = {    ' no ': 1,    ' name ': ' Runoob ',    ' url ': ' Http://www.runoob.com '}json_ str = json.dumps (data) print ("Python raw Data:", repr (data)) print ("JSON object:", Json_str)

 

Second, json.loads ()

Convert a JSON object into a python dictionary

# convert JSON object to Python dictionary data2 = json.loads (json_str) print ("data2[' name ']:", data2[' name ']) print ("data2[' url ']:", data2 [' URL '])

Third, Json.dump

Writes a serialized string to a file

Iv. Json.load

Read the contents of a file from a file

#然后来介绍dump方法 # import json# d1 = {' name ': ' Foot '} #这一步就会把d1做序列化处理后的字符串写到db这个文件中 # Json.dump (D1,open (' db ', ' W ')) # D1 = Json.load (Open (' db ', ' R ')) # print (D1,type (D1)) # {' Name ': ' Foot '} <class ' Dict ' >

  

The use of JSON modules for Python interface testing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.