python lstrip,rstrip 的 用法

#方法一:
import json
s = '({"freight":[{"beforeSpecifiedTime":false,"cityCode":"","cityName":"","commitDay":60,"company":"CAINIAO_STANDARD","companyDisplayName":"AliExpress Standard Shipping","coreZone":"","currency":"USD","cutTime":"17:00","deliveryDate":"2019-09-20","deliveryDateDisplay":"other","discount":93,"discountType":"about","domesticFreight":"","errorCode":1,"errorDisplayMsg":"","isCheapestFaster":false,"isDefault":true,"isPromote":false,"isTracked":true,"localCurrency":"USD","localPrice":"0.35","localPriceFormatStr":"US $0.35","localSaveMoney":"5.02","localSaveMoneyFormatStr":"US $5.02","localTotalFreight":"5.37","localTotalFreightFormatStr":"US $5.37","logisticsDeliveryTimeType":"BUYER_PAY_ORDER","notification":"","price":"0.35","priceFormatStr":"US $0.35","processingTime":5,"promoteInformation":null,"remainTime":"-9475079","saveMoney":"5.02","saveMoneyFormatStr":"US $5.02","sendGoodsCountry":"CN","sendGoodsCountryFullName":"China","status":"","templateDiscount":"","templateType":"","time":"22","totalFreight":"5.37","totalFreightFormatStr":"US $5.37"},{"beforeSpecifiedTime":false,"cityCode":"","cityName":"","commitDay":60,"company":"EMS_ZX_ZX_US","companyDisplayName":"ePacket","coreZone":"","currency":"USD","cutTime":"17:00","deliveryDate":"2019-09-19","deliveryDateDisplay":"other","discount":74,"discountType":"about","domesticFreight":"","errorCode":1,"errorDisplayMsg":"","isCheapestFaster":false,"isDefault":false,"isPromote":false,"isTracked":true,"localCurrency":"USD","localPrice":"1.04","localPriceFormatStr":"US $1.04","localSaveMoney":"2.98","localSaveMoneyFormatStr":"US $2.98","localTotalFreight":"4.02","localTotalFreightFormatStr":"US $4.02","logisticsDeliveryTimeType":"BUYER_PAY_ORDER","notification":"","price":"1.04","priceFormatStr":"US $1.04","processingTime":5,"promoteInformation":null,"remainTime":"-9475079","saveMoney":"2.98","saveMoneyFormatStr":"US $2.98","sendGoodsCountry":"CN","sendGoodsCountryFullName":"China","status":"","templateDiscount":"","templateType":"","time":"21","totalFreight":"4.02","totalFreightFormatStr":"US $4.02"}]})'
#注意這個s是字符類型的
s1 = s.lstrip('(') #去除左括號
s = s1.rstrip(')') #去除右括號
s_dic = json.loads(s) #將字符串轉成字典
print(s_dic)

 #方法二:python

  使用eval()進行處理。json

相關文章
相關標籤/搜索