- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我很难理解为什么以下输出(应该是 json 格式,并且是从数据库查询生成的)不可解析。
dbresponse = """
(('{"stopApprovalInd":true,"nonPersonalizedCardLine3":"Valued Cardholder","productRoutingBins":[{"requestType":"DIGITAL_ACCOUNT_REQUEST","bin":"342010002"}],"holdtimeSeconds":0,"defaultUpcInd":"false","updatedTimestamp":"2019-01-23T18:53:26.261Z","productName":"PB EGIFT (CAG) MAYO\'S $100","reloadMaxAmount":0,"issuerCompanyCode":"BKPB","updaterId":"IIKIFFFFFFPDZ0PDNQBGWMVGMRVTK9DM","sellStartDate":"2018-08-20T00:00:00.000+0000","taxIncludedInd":false,"taxPercent":0,"maxValueAmount":100,"proxyCardLength":19,"inventorySource":"BLAST","postReversalInd":false,"distributionChannel":"DIGITAL","multicardFlag":"N","companyCode":"BKPB","indentDataType":"0","activateOnShipment":"false","productRedemptionMethods":[],"upc":"07675030446","productFees":[{"feeAmount":0,"feeType":"PURCHASE"},{"feeAmount":0,"feeType":"TRANSACTION"},{"feeAmount":0,"feeType":"CUSTOMIZATION"}],"cpDivisionId":"2X2A9M5KRLXQWQ1SB","subGroupId":"YVAAN33PV7MZ3Z49V0F0J","defaultProductConfigurationId":"Y56X4RXNCY2R9ACSDH","isContentEnabled":false,"productFulfillments":[{"fulfillmentMethod":"EMAIL","fulfillmentType":"PRINT_ON_DEMAND"}],"taxAmount":0,"redeemLocationInd":false,"taxableInd":false,"productRedemptionLocations":[],"generationType":"0","serviceCode":"121","processorCompanyCode":"HP","productDisplayname":"MAYO\'s $100 eGift","baseValueAmount":100,"creatorId":"IIKIFFFFFFPDZ0PDNQBGWMVGMRVTK9DM","subsequentActivation":false,"generateProxyCardNumberInd":false,"productCategory":"CLOSELOOP","exclusionInd":false,"reloadableInd":false,"reversibleInd":false,"productLocale":[{"redemptionInstructions":"<p>Your E-gift Card is redeemable online at mayo.com and in \'s stores nationwide.<\\/p>","productTemplates":[{"templateType":"PRODUCTION","templateId":"Z6WSTWN9HABX8","templatePath":"https://blahblah.net/gcmimages/View/WGNX8/index.html"}],"localeCode":"en_US","inStoreInstructions":"<p>In Store: Print this entire page, and present it to a Mayo\'s Associate at checkout.<\\/p>","onlineInstructions":"<p>Online: Enter your E-Gift Card Number at checkout in the PAY WITH GIFT CARD box. If you have any questions, or to check your balance, please call 1-800-511-2752.<br>You may also scan your printed barcode at a price checker terminal in stores.<br>Your Mayo\'s E-Gift Card number is required for all inquiries.<\\/p>","productDescription":"Mayo\'s, the largest retail brand of Mayo\'s, Inc. (NYSE:M), delivers fashion and affordable luxury to customers at approximately 670 locations in 45 states, the District of Columbia, Puerto Rico and Guam, as well as to customers in the U.S. and more than 100 international destinations through its leading online store at macys.com. Via its stores, e-commerce site, mobile and social platforms, Mayo\'s offers distinctive assortments including the most desired family of exclusive and fashion brands for him, her and home. Mayo\'s is known for such epic events as Mayo\'s 4th of July Fireworks\xae and the Mayo\'s Thanksgiving Day Parade\xae. Building on a more than 150-year tradition, and with the collective support of customers and employees, Mayo\'s helps strengthen communities by supporting local and national charities giving more than $69 million each year to help make a difference in the lives of our customers","termsAndConditions":"Your Mayo\'s E-Gift Card number may be used to purchase any merchandise on-line at macys.com or in-store by following the instructions in the E-Gift Card email. You may not add value back onto the E-Gift Card, nor redeem it for cash or apply it as payment or credit to your credit card account. When you make a purchase with your E-Gift Card number, the value of your purchase plus any shipping/handling fees and sales tax, if applicable, will be automatically deducted from your \\"open to buy.\\" You may check any remaining value via the online Balance Inquiry function, or in-store by scanning the barcode at a price checker terminal or by calling 1-800-511-2752. Please safeguard your Mayo\'s E-Gift Card number. The bearer is responsible for its loss or theft. If your E-Gift Card is lost or stolen, and you have proof of purchase, we will issue you a replacement for the balance shown on our records. Your macys.com E-Gift Card number is required for all inquiries."}],"cardExpirationType":"0","productBarcodes":[{"barcodeType":"1D-CA128"}],"feeStrippingInd":false,"productLineId":"3G2D6R3YG85WZ570","createdTimestamp":"2018-08-20T18:53:46.435Z","inventoryLoadType":"HOT","variableInd":false,"isForcedResponseProduct":false,"reloadMinAmount":0,"entityId":"6APACRYFLXTLSKS","itemBuyerGroupId":"FASHION","provisioningType":"DIGITAL","productFulfillmentPartners":[],"currencyCode":"USD","proxyBin":"0"}',),)
"""
我不能将其视为 json,因为当我对数据(直接来自数据库)执行 type(dbresponse)
时,python 告诉我它是一个“元组”数据。但我知道为了能够访问这些值,Python 需要将数据视为字典。
我尝试了多种不同的方式来转换它,但都无济于事。
str(dbresponse)
eval(dict(dbresponse))
str(list(dbresponse)) # tried to convert it to a list, then to a str in hopes of then being able to convert it to dictionary. didnt work.
我对json了解不多。
我的问题是,是否有一种万无一失的方法可以将上述数据从元组转换/转换为字典?完成后,我如何迭代数据中的所有键/值,以便查看可用的内容。
我尝试了 pprinnt
( pretty-print ),但这对我来说不太清楚(我可能使用不正确)。
最佳答案
如果您的响应确实是一个字符串,如下所示,并且始终具有相同的格式,您可以删除开头的 (('
和 ',),)
在最后。其余部分是有效的 JSON 字符串:
import json
dbresponse = """(('{"stopApprovalInd":true,"nonPersonalizedCardLine3":"Valued Cardholder","productRoutingBins":[{"requestType":"DIGITAL_ACCOUNT_REQUEST","bin":"342010002"}],"holdtimeSeconds":0,"defaultUpcInd":"false","updatedTimestamp":"2019-01-23T18:53:26.261Z","productName":"PB EGIFT (CASHSTAR) MACY\'S $100","reloadMaxAmount":0,"issuerCompanyCode":"BKPB","updaterId":"IIKIFFFFFFPDZ0PDNQBGWMVGMRVTK9DM","sellStartDate":"2018-08-20T00:00:00.000+0000","taxIncludedInd":false,"taxPercent":0,"maxValueAmount":100,"proxyCardLength":19,"inventorySource":"BLAST","postReversalInd":false,"distributionChannel":"DIGITAL","multicardFlag":"N","companyCode":"BKPB","indentDataType":"0","activateOnShipment":"false","productRedemptionMethods":[],"upc":"07675030446","productFees":[{"feeAmount":0,"feeType":"PURCHASE"},{"feeAmount":0,"feeType":"TRANSACTION"},{"feeAmount":0,"feeType":"CUSTOMIZATION"}],"cpDivisionId":"2X2A9M5KRLXQWQ1SB","subGroupId":"YVAAN33PV7MZ3Z49V0F0J","defaultProductConfigurationId":"Y56X4RXNCY2R9ACSDH","isContentEnabled":false,"productFulfillments":[{"fulfillmentMethod":"EMAIL","fulfillmentType":"PRINT_ON_DEMAND"}],"taxAmount":0,"redeemLocationInd":false,"taxableInd":false,"productRedemptionLocations":[],"generationType":"0","serviceCode":"121","processorCompanyCode":"HP","productDisplayname":"Macy\'s $100 eGift","baseValueAmount":100,"creatorId":"IIKIFFFFFFPDZ0PDNQBGWMVGMRVTK9DM","subsequentActivation":false,"generateProxyCardNumberInd":false,"productCategory":"CLOSELOOP","exclusionInd":false,"reloadableInd":false,"reversibleInd":false,"productLocale":[{"redemptionInstructions":"<p>Your E-gift Card is redeemable online at macys.com and in Macy\'s stores nationwide.<\\/p>","productTemplates":[{"templateType":"PRODUCTION","templateId":"Z6WSTWN9HABX8","templatePath":"https://blahblah.net/gcmimages/View/WGNX8/index.html"}],"localeCode":"en_US","inStoreInstructions":"<p>In Store: Print this entire page, and present it to a Macy\'s Associate at checkout.<\\/p>","onlineInstructions":"<p>Online: Enter your E-Gift Card Number at checkout in the PAY WITH GIFT CARD box. If you have any questions, or to check your balance, please call 1-800-511-2752.<br>You may also scan your printed barcode at a price checker terminal in stores.<br>Your Macy\'s E-Gift Card number is required for all inquiries.<\\/p>","productDescription":"Macy\'s, the largest retail brand of Macy\'s, Inc. (NYSE:M), delivers fashion and affordable luxury to customers at approximately 670 locations in 45 states, the District of Columbia, Puerto Rico and Guam, as well as to customers in the U.S. and more than 100 international destinations through its leading online store at macys.com. Via its stores, e-commerce site, mobile and social platforms, Macy\'s offers distinctive assortments including the most desired family of exclusive and fashion brands for him, her and home. Macy\'s is known for such epic events as Macy\'s 4th of July Fireworks\xae and the Macy\'s Thanksgiving Day Parade\xae. Building on a more than 150-year tradition, and with the collective support of customers and employees, Macy\'s helps strengthen communities by supporting local and national charities giving more than $69 million each year to help make a difference in the lives of our customers","termsAndConditions":"Your Macy\'s E-Gift Card number may be used to purchase any merchandise on-line at macys.com or in-store by following the instructions in the E-Gift Card email. You may not add value back onto the E-Gift Card, nor redeem it for cash or apply it as payment or credit to your credit card account. When you make a purchase with your E-Gift Card number, the value of your purchase plus any shipping/handling fees and sales tax, if applicable, will be automatically deducted from your \\"open to buy.\\" You may check any remaining value via the online Balance Inquiry function, or in-store by scanning the barcode at a price checker terminal or by calling 1-800-511-2752. Please safeguard your Macy\'s E-Gift Card number. The bearer is responsible for its loss or theft. If your E-Gift Card is lost or stolen, and you have proof of purchase, we will issue you a replacement for the balance shown on our records. Your macys.com E-Gift Card number is required for all inquiries."}],"cardExpirationType":"0","productBarcodes":[{"barcodeType":"1D-CA128"}],"feeStrippingInd":false,"productLineId":"3G2D6R3YG85WZ570","createdTimestamp":"2018-08-20T18:53:46.435Z","inventoryLoadType":"HOT","variableInd":false,"isForcedResponseProduct":false,"reloadMinAmount":0,"entityId":"6APACRYFLXTLSKS","itemBuyerGroupId":"FASHION","provisioningType":"DIGITAL","productFulfillmentPartners":[],"currencyCode":"USD","proxyBin":"0"}',),)"""
json_str = dbresponse[3:-5]
data = json.loads(json_str)
print(data)
# {'stopApprovalInd': True, 'nonPersonalizedCardLine3': 'Valued Cardholder', 'productRoutingBins': [{'requestType': 'DIGITAL_ACCOUNT_REQUEST', 'bin': '342010002'}], 'holdtimeSeconds': 0, 'defaultUpcInd': 'false', 'updatedTimestamp': '2019-01-23T18:53:26.261Z', 'productName': "PB EGIFT (CASHSTAR) MACY'S $100", 'reloadMaxAmount': 0, 'issuerCompanyCode': ...
print(data['stopApprovalInd'])
# True
关于元组格式的python json数据不可解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55085607/
typing模块中使用List、Tuple等有什么区别: from typing import Tuple def f(points: Tuple): return map(do_stuff,
如何遍历列表的每 5 个元素并将它们组成一个元组,然后将同一列表的第 6 个元素作为第二个元组 - 然后对接下来的 5 个元素和第 6 个元素执行相同的操作。 我读过 operator.itemget
我有一个 Seq[((元组 A),(元组 B))] 有没有一种简单的方法来对元组 A 进行分组,以便我得到 Seq[(Tuple A, Seq[Tuple B])] 我试过 groupby(x =>
如果我有以下内容 val A = List(1,2,3) val B = List(1,2,3) 这两个变量是否有相同的内存地址? 最佳答案 它们不会有相同的内存地址,可以使用 eq 方法确认,com
我实际上是在尝试创建一个配对列表,但事实证明这非常困难 在有人提到 Hashtables 之前请注意,会有我不关心的重复项。 例如,如果我这样做 $b = @{"dog" = "cat"} 我明白了
我正在尝试为其他资源中的 for_each 循环创建局部变量,但无法按预期制作局部映射。 以下是我试过的。 (地形 0.12) 预期映射到循环 temple_list = { "test2-role"
我目前正在学习 Haskell,在 FP 方面我绝对是初学者。 现在我正在尝试使用列表推导式进行不同的操作。 listComprehension = [(a,b,c) | a <- xs, b <
我正在尝试为其他资源中的 for_each 循环创建局部变量,但无法按预期制作局部映射。 以下是我试过的。 (地形 0.12) 预期映射到循环 temple_list = { "test2-role"
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve th
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
如何通过元组中的第三项过滤此类型的列表: type Car = (String, [String], Int [String]) 我看到了 snd和 fst方法,但在这里我认为这行不通,我不确定如何在
有没有办法创建 Tuple 在 Java 中,无需创建多个类? 例如,可以为每种不同类型的元组创建不同的类,每个类具有不同数量的 Type Parameters : public class Sing
我必须处理一堆二维点类型:pair , pair , pair ,并且只要存在坐标转换,我就允许点之间的隐式转换。像这样: template inline operator pair ( pair t
这个问题在这里已经有了答案: How do I iterate through two lists in parallel? (8 个答案) How do I iterate over the tu
编写一个函数 square_odd_terms 接受一个元组作为参数并返回一个元组中奇数项的平方的元组。即使是条款也将保持不变。 我的尝试是: def square_odd_termms(tpl):
更新: 我选择了这个: set(item[1] for item in id) 谢谢你们,你们的想法对我有帮助。 我正在处理一个元组列表: 以下面这行代码为例。我的 list 可以是任何长度。但是,我
我一直在尝试执行此任务,在尝试时我不禁想到会有比我一直尝试的方式更好的编码方式。 我有一行文字和一个关键字。我想在每个列表中的每个字符下创建一个新列表。关键字将重复自身直到列表末尾。如果有任何非字母字
我现在这个问题已经被问过好几次了。但是,答案似乎并没有解决我的问题。我收到类型错误,“元组”对象不可调用。即使列表中的元组以正确的方式用逗号分隔,我也得到了这个: def aiMove(b):
嘿,所以我花了两个多小时试图解决这个问题,但我就是做不对。我猜我犯了一个非常简单的错误,所以如果有人能指出我正确的方向,我将非常感激,谢谢!顺便说一句,这是一门树屋类(class)。 “目前我们的问候
这不是一个严格的编程问题,但为什么是tuple在单独的 header 中定义,而不是添加到 连同 pair ?它看起来更自然,不那么困惑等。 最佳答案 在具有细粒度的 header 和只有一个 hea
我是一名优秀的程序员,十分优秀!