Created
August 19, 2015 10:56
-
-
Save anupkalburgi/9365697dd21fe7d2277c to your computer and use it in GitHub Desktop.
Tmp Testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> import json | |
>>> json_str = """{ | |
... "COU": { | |
... "Data": "[{ Title: 'Sports Footwear', image: 'http://coupontown.cloudapp.net/CouponResource/images/Fashion/shoe.jpeg', Description: 'Below Rs.999, Sparx | Fila | Lotto', DiscountDetails: '10%-30%', Category: 'Fashion', CouponId: '1', StartDate: '8/12/2015 11:00:00 AM', Expiredate: '8/30/2015 11:59:00 PM', ExpiryInDay: '18:12:59'},{ Title: 'launching MI Mobile', image: 'http://coupontown.cloudapp.net/CouponResource/images/Electronics/onida-leoTV.jpeg', Description: 'Rs. 6,999, EMI from Rs. 340, 4.7 inch HD IPS Disp...4G LTE, Dual SIM, Camera: 8MP|2MP, 64-bit, Snapdragon 410', DiscountDetails: '10% Off', Category: 'Electronics', CouponId: '2', StartDate: '8/12/2015 11:00:00 AM', Expiredate: '8/25/2015 11:59:00 PM', ExpiryInDay: '13:12:59'},{ Title: 'Laptops with best deal', image: 'http://coupontown.cloudapp.net/CouponResource/images/Electronics/hp-notebook.jpeg', Description: 'Top Brand laptops in very less price', DiscountDetails: '20%-50%', Category: 'Electronics', CouponId: '3', StartDate: '8/13/2015 6:45:00 PM', Expiredate: '8/24/2015 11:59:00 PM', ExpiryInDay: '11:5:14'}]" | |
... } | |
... }""" | |
>>> | |
>>> json_str | |
'{\n "COU": {\n "Data": "[{ Title: \'Sports Footwear\', image: \'http://coupontown.cloudapp.net/CouponResource/images/Fashion/shoe.jpeg\', Description: \'Below Rs.999, Sparx | Fila | Lotto\', DiscountDetails: \'10%-30%\', Category: \'Fashion\', CouponId: \'1\', StartDate: \'8/12/2015 11:00:00 AM\', Expiredate: \'8/30/2015 11:59:00 PM\', ExpiryInDay: \'18:12:59\'},{ Title: \'launching MI Mobile\', image: \'http://coupontown.cloudapp.net/CouponResource/images/Electronics/onida-leoTV.jpeg\', Description: \'Rs. 6,999, EMI from Rs. 340, 4.7 inch HD IPS Disp...4G LTE, Dual SIM, Camera: 8MP|2MP, 64-bit, Snapdragon 410\', DiscountDetails: \'10% Off\', Category: \'Electronics\', CouponId: \'2\', StartDate: \'8/12/2015 11:00:00 AM\', Expiredate: \'8/25/2015 11:59:00 PM\', ExpiryInDay: \'13:12:59\'},{ Title: \'Laptops with best deal\', image: \'http://coupontown.cloudapp.net/CouponResource/images/Electronics/hp-notebook.jpeg\', Description: \'Top Brand laptops in very less price\', DiscountDetails: \'20%-50%\', Category: \'Electronics\', CouponId: \'3\', StartDate: \'8/13/2015 6:45:00 PM\', Expiredate: \'8/24/2015 11:59:00 PM\', ExpiryInDay: \'11:5:14\'}]"\n }\n}' | |
>>> | |
>>> json.dump(json_str) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
TypeError: dump() takes at least 2 arguments (1 given) | |
>>> | |
>>> json.loads(json_str) | |
{u'COU': {u'Data': u"[{ Title: 'Sports Footwear', image: 'http://coupontown.cloudapp.net/CouponResource/images/Fashion/shoe.jpeg', Description: 'Below Rs.999, Sparx | Fila | Lotto', DiscountDetails: '10%-30%', Category: 'Fashion', CouponId: '1', StartDate: '8/12/2015 11:00:00 AM', Expiredate: '8/30/2015 11:59:00 PM', ExpiryInDay: '18:12:59'},{ Title: 'launching MI Mobile', image: 'http://coupontown.cloudapp.net/CouponResource/images/Electronics/onida-leoTV.jpeg', Description: 'Rs. 6,999, EMI from Rs. 340, 4.7 inch HD IPS Disp...4G LTE, Dual SIM, Camera: 8MP|2MP, 64-bit, Snapdragon 410', DiscountDetails: '10% Off', Category: 'Electronics', CouponId: '2', StartDate: '8/12/2015 11:00:00 AM', Expiredate: '8/25/2015 11:59:00 PM', ExpiryInDay: '13:12:59'},{ Title: 'Laptops with best deal', image: 'http://coupontown.cloudapp.net/CouponResource/images/Electronics/hp-notebook.jpeg', Description: 'Top Brand laptops in very less price', DiscountDetails: '20%-50%', Category: 'Electronics', CouponId: '3', StartDate: '8/13/2015 6:45:00 PM', Expiredate: '8/24/2015 11:59:00 PM', ExpiryInDay: '11:5:14'}]"}} | |
>>> | |
>>> | |
>>> | |
>>> resp = json.loads(json_str) | |
>>> | |
>>> resp | |
{u'COU': {u'Data': u"[{ Title: 'Sports Footwear', image: 'http://coupontown.cloudapp.net/CouponResource/images/Fashion/shoe.jpeg', Description: 'Below Rs.999, Sparx | Fila | Lotto', DiscountDetails: '10%-30%', Category: 'Fashion', CouponId: '1', StartDate: '8/12/2015 11:00:00 AM', Expiredate: '8/30/2015 11:59:00 PM', ExpiryInDay: '18:12:59'},{ Title: 'launching MI Mobile', image: 'http://coupontown.cloudapp.net/CouponResource/images/Electronics/onida-leoTV.jpeg', Description: 'Rs. 6,999, EMI from Rs. 340, 4.7 inch HD IPS Disp...4G LTE, Dual SIM, Camera: 8MP|2MP, 64-bit, Snapdragon 410', DiscountDetails: '10% Off', Category: 'Electronics', CouponId: '2', StartDate: '8/12/2015 11:00:00 AM', Expiredate: '8/25/2015 11:59:00 PM', ExpiryInDay: '13:12:59'},{ Title: 'Laptops with best deal', image: 'http://coupontown.cloudapp.net/CouponResource/images/Electronics/hp-notebook.jpeg', Description: 'Top Brand laptops in very less price', DiscountDetails: '20%-50%', Category: 'Electronics', CouponId: '3', StartDate: '8/13/2015 6:45:00 PM', Expiredate: '8/24/2015 11:59:00 PM', ExpiryInDay: '11:5:14'}]"}} | |
>>> | |
>>> | |
>>> resp.keys() | |
[u'COU'] | |
>>> | |
>>> resp['COU'] | |
{u'Data': u"[{ Title: 'Sports Footwear', image: 'http://coupontown.cloudapp.net/CouponResource/images/Fashion/shoe.jpeg', Description: 'Below Rs.999, Sparx | Fila | Lotto', DiscountDetails: '10%-30%', Category: 'Fashion', CouponId: '1', StartDate: '8/12/2015 11:00:00 AM', Expiredate: '8/30/2015 11:59:00 PM', ExpiryInDay: '18:12:59'},{ Title: 'launching MI Mobile', image: 'http://coupontown.cloudapp.net/CouponResource/images/Electronics/onida-leoTV.jpeg', Description: 'Rs. 6,999, EMI from Rs. 340, 4.7 inch HD IPS Disp...4G LTE, Dual SIM, Camera: 8MP|2MP, 64-bit, Snapdragon 410', DiscountDetails: '10% Off', Category: 'Electronics', CouponId: '2', StartDate: '8/12/2015 11:00:00 AM', Expiredate: '8/25/2015 11:59:00 PM', ExpiryInDay: '13:12:59'},{ Title: 'Laptops with best deal', image: 'http://coupontown.cloudapp.net/CouponResource/images/Electronics/hp-notebook.jpeg', Description: 'Top Brand laptops in very less price', DiscountDetails: '20%-50%', Category: 'Electronics', CouponId: '3', StartDate: '8/13/2015 6:45:00 PM', Expiredate: '8/24/2015 11:59:00 PM', ExpiryInDay: '11:5:14'}]"} | |
>>> | |
>>> resp['COU']['Data'] | |
u"[{ Title: 'Sports Footwear', image: 'http://coupontown.cloudapp.net/CouponResource/images/Fashion/shoe.jpeg', Description: 'Below Rs.999, Sparx | Fila | Lotto', DiscountDetails: '10%-30%', Category: 'Fashion', CouponId: '1', StartDate: '8/12/2015 11:00:00 AM', Expiredate: '8/30/2015 11:59:00 PM', ExpiryInDay: '18:12:59'},{ Title: 'launching MI Mobile', image: 'http://coupontown.cloudapp.net/CouponResource/images/Electronics/onida-leoTV.jpeg', Description: 'Rs. 6,999, EMI from Rs. 340, 4.7 inch HD IPS Disp...4G LTE, Dual SIM, Camera: 8MP|2MP, 64-bit, Snapdragon 410', DiscountDetails: '10% Off', Category: 'Electronics', CouponId: '2', StartDate: '8/12/2015 11:00:00 AM', Expiredate: '8/25/2015 11:59:00 PM', ExpiryInDay: '13:12:59'},{ Title: 'Laptops with best deal', image: 'http://coupontown.cloudapp.net/CouponResource/images/Electronics/hp-notebook.jpeg', Description: 'Top Brand laptops in very less price', DiscountDetails: '20%-50%', Category: 'Electronics', CouponId: '3', StartDate: '8/13/2015 6:45:00 PM', Expiredate: '8/24/2015 11:59:00 PM', ExpiryInDay: '11:5:14'}]" | |
>>> | |
>>> | |
>>> | |
>>> resp['COU']['Data'][0] | |
u'[' | |
>>> resp['COU']['Data'] | |
u"[{ Title: 'Sports Footwear', image: 'http://coupontown.cloudapp.net/CouponResource/images/Fashion/shoe.jpeg', Description: 'Below Rs.999, Sparx | Fila | Lotto', DiscountDetails: '10%-30%', Category: 'Fashion', CouponId: '1', StartDate: '8/12/2015 11:00:00 AM', Expiredate: '8/30/2015 11:59:00 PM', ExpiryInDay: '18:12:59'},{ Title: 'launching MI Mobile', image: 'http://coupontown.cloudapp.net/CouponResource/images/Electronics/onida-leoTV.jpeg', Description: 'Rs. 6,999, EMI from Rs. 340, 4.7 inch HD IPS Disp...4G LTE, Dual SIM, Camera: 8MP|2MP, 64-bit, Snapdragon 410', DiscountDetails: '10% Off', Category: 'Electronics', CouponId: '2', StartDate: '8/12/2015 11:00:00 AM', Expiredate: '8/25/2015 11:59:00 PM', ExpiryInDay: '13:12:59'},{ Title: 'Laptops with best deal', image: 'http://coupontown.cloudapp.net/CouponResource/images/Electronics/hp-notebook.jpeg', Description: 'Top Brand laptops in very less price', DiscountDetails: '20%-50%', Category: 'Electronics', CouponId: '3', StartDate: '8/13/2015 6:45:00 PM', Expiredate: '8/24/2015 11:59:00 PM', ExpiryInDay: '11:5:14'}]" | |
>>> | |
>>> | |
>>> | |
>>> type(resp['COU']['Data']) | |
<type 'unicode'> | |
>>> | |
>>> | |
>>> data = resp['COU']['Data'] | |
>>> json.loads(data) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads | |
return _default_decoder.decode(s) | |
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 366, in decode | |
obj, end = self.raw_decode(s, idx=_w(s, 0).end()) | |
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 382, in raw_decode | |
obj, end = self.scan_once(s, idx) | |
ValueError: Expecting property name enclosed in double quotes: line 1 column 4 (char 3) | |
>>> | |
>>> | |
>>> data | |
u"[{ Title: 'Sports Footwear', image: 'http://coupontown.cloudapp.net/CouponResource/images/Fashion/shoe.jpeg', Description: 'Below Rs.999, Sparx | Fila | Lotto', DiscountDetails: '10%-30%', Category: 'Fashion', CouponId: '1', StartDate: '8/12/2015 11:00:00 AM', Expiredate: '8/30/2015 11:59:00 PM', ExpiryInDay: '18:12:59'},{ Title: 'launching MI Mobile', image: 'http://coupontown.cloudapp.net/CouponResource/images/Electronics/onida-leoTV.jpeg', Description: 'Rs. 6,999, EMI from Rs. 340, 4.7 inch HD IPS Disp...4G LTE, Dual SIM, Camera: 8MP|2MP, 64-bit, Snapdragon 410', DiscountDetails: '10% Off', Category: 'Electronics', CouponId: '2', StartDate: '8/12/2015 11:00:00 AM', Expiredate: '8/25/2015 11:59:00 PM', ExpiryInDay: '13:12:59'},{ Title: 'Laptops with best deal', image: 'http://coupontown.cloudapp.net/CouponResource/images/Electronics/hp-notebook.jpeg', Description: 'Top Brand laptops in very less price', DiscountDetails: '20%-50%', Category: 'Electronics', CouponId: '3', StartDate: '8/13/2015 6:45:00 PM', Expiredate: '8/24/2015 11:59:00 PM', ExpiryInDay: '11:5:14'}]" | |
>>> | |
>>> | |
>>> data[0] | |
u'[' | |
>>> | |
>>> json.dumps(data) | |
'"[{ Title: \'Sports Footwear\', image: \'http://coupontown.cloudapp.net/CouponResource/images/Fashion/shoe.jpeg\', Description: \'Below Rs.999, Sparx | Fila | Lotto\', DiscountDetails: \'10%-30%\', Category: \'Fashion\', CouponId: \'1\', StartDate: \'8/12/2015 11:00:00 AM\', Expiredate: \'8/30/2015 11:59:00 PM\', ExpiryInDay: \'18:12:59\'},{ Title: \'launching MI Mobile\', image: \'http://coupontown.cloudapp.net/CouponResource/images/Electronics/onida-leoTV.jpeg\', Description: \'Rs. 6,999, EMI from Rs. 340, 4.7 inch HD IPS Disp...4G LTE, Dual SIM, Camera: 8MP|2MP, 64-bit, Snapdragon 410\', DiscountDetails: \'10% Off\', Category: \'Electronics\', CouponId: \'2\', StartDate: \'8/12/2015 11:00:00 AM\', Expiredate: \'8/25/2015 11:59:00 PM\', ExpiryInDay: \'13:12:59\'},{ Title: \'Laptops with best deal\', image: \'http://coupontown.cloudapp.net/CouponResource/images/Electronics/hp-notebook.jpeg\', Description: \'Top Brand laptops in very less price\', DiscountDetails: \'20%-50%\', Category: \'Electronics\', CouponId: \'3\', StartDate: \'8/13/2015 6:45:00 PM\', Expiredate: \'8/24/2015 11:59:00 PM\', ExpiryInDay: \'11:5:14\'}]"' | |
>>> | |
>>> | |
>>> tmp = json.dumps(data) | |
>>> type(tmp) | |
<type 'str'> | |
>>> json.loads(tmp) | |
u"[{ Title: 'Sports Footwear', image: 'http://coupontown.cloudapp.net/CouponResource/images/Fashion/shoe.jpeg', Description: 'Below Rs.999, Sparx | Fila | Lotto', DiscountDetails: '10%-30%', Category: 'Fashion', CouponId: '1', StartDate: '8/12/2015 11:00:00 AM', Expiredate: '8/30/2015 11:59:00 PM', ExpiryInDay: '18:12:59'},{ Title: 'launching MI Mobile', image: 'http://coupontown.cloudapp.net/CouponResource/images/Electronics/onida-leoTV.jpeg', Description: 'Rs. 6,999, EMI from Rs. 340, 4.7 inch HD IPS Disp...4G LTE, Dual SIM, Camera: 8MP|2MP, 64-bit, Snapdragon 410', DiscountDetails: '10% Off', Category: 'Electronics', CouponId: '2', StartDate: '8/12/2015 11:00:00 AM', Expiredate: '8/25/2015 11:59:00 PM', ExpiryInDay: '13:12:59'},{ Title: 'Laptops with best deal', image: 'http://coupontown.cloudapp.net/CouponResource/images/Electronics/hp-notebook.jpeg', Description: 'Top Brand laptops in very less price', DiscountDetails: '20%-50%', Category: 'Electronics', CouponId: '3', StartDate: '8/13/2015 6:45:00 PM', Expiredate: '8/24/2015 11:59:00 PM', ExpiryInDay: '11:5:14'}]" | |
>>> | |
>>> | |
>>> | |
>>> rep = json.loads(tmp) | |
>>> rep.keys() | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
AttributeError: 'unicode' object has no attribute 'keys' | |
>>> | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment