加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python lstrip,rstrip 的 用法

发布时间:2020-12-20 10:50:25 所属栏目:Python 来源:网络整理
导读:#方法一: import json s = ‘({"freight":[{"beforeSpecifiedTime":false,"cityCode":"","cityName":"","commitDay":60,"company":"CAINIAO_STANDARD","companyDisplayName":"AliExpress Standard Shipping","coreZone":"","currency":"USD","cutTime":"17:
#方法一:
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,"company":"EMS_ZX_ZX_US","companyDisplayName":"ePacket","deliveryDate":"2019-09-19","discount":74,"isDefault":false,"localPrice":"1.04","localPriceFormatStr":"US $1.04","localSaveMoney":"2.98","localSaveMoneyFormatStr":"US $2.98","localTotalFreight":"4.02","localTotalFreightFormatStr":"US $4.02","price":"1.04","priceFormatStr":"US $1.04","saveMoney":"2.98","saveMoneyFormatStr":"US $2.98","time":"21","totalFreight":"4.02","totalFreightFormatStr":"US $4.02"}]})‘
#注意这个s是字符类型的
s1 = s.lstrip(‘(‘) #去除左括号
s = s1.rstrip(‘)‘) #去除右括号
s_dic = json.loads(s) #将字符串转成字典
print(s_dic)

 #方法二:

  使用eval()进行处理。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读