python用json转csv

来源:互联网 发布:樱井知香作品封面番号 编辑:程序博客网 时间:2024/05/22 01:43
# -*- coding: utf-8 -*-
"""
Created on Wed May 31 14:07:54 2017

@author: ESRI
"""

import json  
import sys



if __name__ == "__main__":
    reload(sys)
    sys.setdefaultencoding( "utf-8" )
 
    f = open('C:/Users/ESRI/Desktop/jqdl10010.json','r')
    fw =  open('C:/Users/ESRI/Desktop/jqdl1000.csv','w')
    setting = json.load(f)
    features =  setting['features']
    for feature in features:
        attr =  feature['attributes']
        FID = attr['FID']
        OBJECTID = attr['OBJECTID']
        BSM = attr['BSM']
        YSDM = attr['YSDM']
        TBBH = attr['TBBH']
        DLMC = attr['DLMC']
        XZQDM = attr['XZQDM']
        DLBZ = attr['DLBZ']
        TBMJ = attr['TBMJ']
        TBDLMJ = attr['TBDLMJ']
        Shape_Leng = attr['Shape_Leng']
        Shape_Area = attr['Shape_Area']
        line = str(FID)+ ',' + str(OBJECTID)+',' +str(BSM)+',' +str(YSDM)+',' +str(TBBH)+',' +str(DLMC)+',' +str(XZQDM)+',' +str(DLBZ)+',' +str(TBMJ)+',' +str(TBDLMJ)+',' +str(Shape_Leng)+',' +str(Shape_Area)
        #print line
                    
    
        fw.write(line + '\n')
    fw.close()   
    
       


原创粉丝点击