Python Foundation 7.7 json--on

Source: Internet
Author: User
Tags string format

I. Use of file JSONJSON introduction: JSON Full name JavaScripts object Notation, is a lightweight data interchange format, the most extensive application of JSON as a Web server and client communication in AIAX data format, is now also used in httpd requests, So the various learning of JSON is a natural thing. The following are the two most common ways of working in peacetime.    #/usr/bin/python#coding =utf-8# @Time: 2017/11/12 22:27# @Auther: Liuzhenchuan# @File: json-on. PY#1. Four ways to JSON# json.loads#json. Dumps#多了个s is the processing of the string, no S is processing the file# Json.load#json. Dump#解释 load/loads: Loads the meaning. is to convert JSON into other formats, strings or file-related#解释: dump/dumps: Upside-down meaning. is to convert other objects or formats into JSON format .#自动解析javascript的网址: json.cn #示例1: Convert python dict format to string formatImport JSON print ' # # # # #json. Dumps () method converts a dictionary to a string format ##### ' A =Dict(name= Lzc ' ,age= ,message= "You're so Corde '" Span style= "Font-family:simsun, Stsong; Font-size:18px ">) print a print type(a) B = Json.dumps (a)print type(b) print b #示例2:print ' # # # # #json. Loads () method converts a string into a dictionary but the encoding is converted to UNIC encoded ##### ' print type(b) C = json.loads (b)print type(c) print c >>># # # # # # # #json Dumps () method converts a dictionary to a string format #####{' message ': ' Corde ', ' age ': ' + ', ' name ': ' Lzc '}<type ' dict ' ><type ' str ' >{"message": "Corde", "Age": "+", "name": "Lzc"}# # # # # # # # # #json the loads () method converts a string into a dictionary but the encoding is converted to UNIC encoding #####<type ' str ' ><type ' dict ' >{u ' message ': U ' corde ', U ' age ': U ' ", U ' name ': U ' lzc '}

Python Foundation 7.7 json--on

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.