Recently someone asked Xiaobian that :Python Developing dictionaries and Json What's the difference ? On this question , Xiao Bian will introduce you through the following .

What is a dictionary ?

A dictionary is a data structure , and json If it is a data format, there will be some formal restrictions , such as json The format of must and can only use double quotation marks as key Or the boundary sign of the value , You can't use single quotes , Using single quotation marks or not using quotation marks will result in reading data errors , and key You have to use a boundary character , But dictionaries don't matter , You can use single quotes , You can also use double quotes .

What is? json?

Literally, it means JavaScript Object notation , here json It means something similar to JavaScript Object is a data format object , At present, this data format is quite popular , Gradually replaced the traditional xml data structure , Front end use ajax The data format that the background returns to the front end is json Format .

Json and dict Difference and contrast ?

Json Of key It can only be a string ,Python Of dict It can be anything hash object ;

Json Of key It can be orderly 、 Repetitive ;dict Of key Not to be repeated ;

Json Of value It can only be a string 、 Floating point numbers 、 Boolean or null, Or an array or object of them ;

Json arbitrarily key There is a default value undefined,dict There is no default value by default ;

Json It can be accessed by [], It can also be ., The traversal mode is different in、of;dict Of value Subscript only access ;

Json Force double quotation marks on the string of ,dict Strings can be single quotes 、 Double quotes ;

Dict Can be nested tuple,json There are only arrays in it ;


Json Chinese must be Unicode code ,jason The type is string , The type of dictionary is dictionary .