Interface Automation test Python (3) _ Use Python to manipulate JSON

Source: Internet
Author: User

How to use Python to perform simple operations on Excel, which is important for interface automation testing

A. Prepare a JSON document in the following format:

{

"Register": {"mobile": "15500000090"},
"Login": {"mobile": "15500000090", "Password": "111111"}

}

1. You may be confused, this format and normal JSON format a little different, the general JSON string is this {"mobile": "15500000090"}

* Written in the above format is mainly to wrap a JSON string, which reduces a lot of code, you can read "register" or "login" in the part of the code, read the real content is contained in the back of the JSON string.

# Coding=utf-8
#ReadJsonContent
Import JSON


ClassOperationjson:
Def__INIT__ (Self):
Self.data =Self.read_data ()

#ReadJsonFile
DefRead_data (Self):
with open ( ". \dataconfig\mobile.json ') as fp:
data = json.load (FP)
return data

# get data by keyword
def get_data (self return Self.data[id]


if __name__ = ' __main__ ':
Opjson = Operationjson ()
print opjson.get_data ( " Login ')

2. We take two steps, the first step is to read the JSON file, the second step through the keyword to get the data content

Two. Allow the script as shown:

Successfully read to JSON string contents

Interface Automation test Python (3) _ Use Python to manipulate JSON

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.