最近在做eBay的对接,所以格式化输出json数组做比对是十分重要的,范例如下
# -*- coding: UTF-8 -*-
import json
data = {'Item': {'ListingType': u'Chinese', 'SubTitle': 'test', 'Title': 'test', 'Country': u'US', 'ConditionID': 1000, 'PaymentMethods': 'PayPal', 'AutoPay': True, 'PayPalEmailAddress': u'dddd', 'Location': u'Afghanistan, Islamic State of, ssss', 'PostalCode': u'10000', 'SellerProfiles': {'SellerPaymentProfile': {'PaymentProfileID': u'5487918000'}, 'SellerReturnProfile': {'ReturnProfileID': u'5596097000'}, 'SellerShippingProfile': {'ShippingProfileID': u'5511516000'}}, 'Quantity': 5, 'Description': u'okok\n \n ]]>', 'ReturnPolicy': {'ReturnsAcceptedOption': u'ReturnsAccepted', 'RefundOption': u'MoneyBack', 'ShippingCostPaidByOption': u'Days_14'}, 'CategoryMappingAllowed': 'true', 'PrivateListing': True, 'ListingDuration': u'Days_30', 'Currency': u'USD', 'ProductListingDetails': {'UPC': 'Does not Apply', 'BrandMPN': {'MPN': 'Does not Apply', 'Brand': 'Unbranded'}, 'EAN': u'6902538004045'}, 'ItemSpecifics': {'NameValueList': [{'Name': 'Brand', 'Value': 'Unbranded'}, {'Name': 'MPN', 'Value': 'Does not Apply'}]}, 'BestOfferDetails': {'BestOfferEnabled': True}, 'PrimaryCategory': {'CategoryID': u'162922'}, 'ShippingDetails': {'ShippingType': u'Flat', 'ExcludeShipToLocation': [u'AX'], 'ShippingServiceOptions': {'FreeShipping': True, 'ShippingService': False, 'ShippingServiceCost': 23.2}, 'InternationalShippingServiceOption': {'ShippingService': False, 'ShipToLocation': [u'AX']}}}}
print json.dumps(data, sort_keys=True, indent=2)
如此长的data真的是让人头疼