-1

I'm doing pythonAPI exercises, and this is my completed API address:

http://api.juheapi.com/japi/toh?key=10245c2b75fa03d527204967ef7291cb&v=1.0&month=07&day=05

If you use the browser to open, the correct JSON file is displayed.but i cant't get correct result using the following codecode .

page = urllib.urlopen(url)
html = page.read() 
dic_json = json.loads(html)
print dic_json
jdehesa
  • 58,456
  • 7
  • 77
  • 121
flystar
  • 85
  • 1
  • 1
  • 8
  • 1
    what error you are getting – Swagat Jul 06 '17 at 11:55
  • sorry,please delete the address ] – flystar Jul 06 '17 at 11:55
  • like this:{u'reason': u'\u8bf7\u6c42\u6210\u529f\uff01', u'error_code': 0, u'result': [{u'des': u'\u5728602\u5e74\u524d\u7684\u4eca\u5929\uff0c1415\u5e747\u67086\u65e5 (\u519c\u5386\u516d\u6708\u521d\u4e00)\uff0c\u6377\u514b\u7684\u7231\u56fd\u4e3b\u4e49\u8005\u80e1\u53f8\u9047\u96be\u3002', – flystar Jul 06 '17 at 11:56
  • What is the wrong in this?? This is a dict type in python. I think you are saying that print statement is not showing the non-english letter, instead showing this `\u8bf7` type value? – Swagat Jul 06 '17 at 11:58
  • @Swagat yes,I can not understand this – flystar Jul 06 '17 at 12:00
  • This is Unicode, when you print in console, it will be print like that for non-asic char – Swagat Jul 06 '17 at 12:01
  • You wouldn't have this problem if you were using Python 3... You may find this article helpful: [Pragmatic Unicode](http://nedbatchelder.com/text/unipain.html), which was written by SO veteran Ned Batchelder. – PM 2Ring Jul 06 '17 at 12:01
  • I tried it, seems to works fine. Cannot understand what is the issue here – Shubham Naik Jul 06 '17 at 12:02
  • 1
    @Swagat I think you mean "non-ASCII character". – PM 2Ring Jul 06 '17 at 12:03
  • Yes @PM2Ring, pardon my typo – Swagat Jul 06 '17 at 12:05

1 Answers1

0

There is nothing error in the json. It successfully parse json to python dict. You should take a look on python unicode. When you try to print a unicode in python 2 you will find like this, but when open in browser it will be correct non-ASCII character.

Python2 store non-ASCII character into like this format.

To read this particular dict , you can do something like this.

for x,y in dic_json.items():
    print x,":", y
Swagat
  • 617
  • 5
  • 16