python lstrip, rstrip usage

# Method One: 
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 # Note that this is a character type of
s1 = s.lstrip ( '(') # remove left bracket
s = s1.rstrip ( ')') # removed right parenthesis
s_dic = json.loads (s) # string transformed into Dictionary
print (s_dic)

 #Method Two:

  Use eval () processing.

  

Guess you like

Origin www.cnblogs.com/fh-fendou/p/11431643.html