Import Json,codecs
def readjson (file):
With open (file, ' RB ') as FP:
data = Json.load (FP)
Return data
List1 = []
Loadjson = Readjson (' Market.json ')
Profile = loadjson[' data ' [' products ']
str1 = ' INSERT into products (ID, name,product_id,long_name,store_nums,specifics,sort,market_price,price, ' \
' Category_id,child_cid,img,keywords,brand_id,brand_name,safe_day,safe_unit,safe_unit_desc ') values '
For k,v in Profile.items ():
For product in V:
str2 = ' '
str2 + = ' ("%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s") ' \
% (str (product[' ID ']), str (product[' name '), str (product[' product_id ')), str (product[' long_name ']), str (product[') Store_nums ']),
STR (product[' specifics '), str (product[' sort ']), str (product[' market_price ']), str (product[' price '), str (product[ ' category_id ']),
Str (product[' child_cid '), str (product[' img "), str (product[' keywords ']), str (product[' brand_id ']), str (product[') Brand_Name ']),
Str (product[' safe_day '), str (product[' safe_unit ']), str (product[' Safe_unit_desc '))
List1.append (STR2)
STR3 = str1+ ', '. Join (List1) + '; '
Print (STR3)
File = Codecs.open (' Market.sql ', ' WB ', ' Utf-8 ')
File.write (STR3)
File.close ()
Print (' ok! ')
JSON data generation MySQL statement