2015-10-16 65 views
-1

我怎样才能输出标题的字母顺序?我希望它能打印'娱乐',然后'信息'。如何排序python中的json输出

注意:这只是一个示例。 JSON文件我跟工作有更多的冠军

>>> import json 
 

 
>>> field = json.loads('{"js":[{"id":"1","title":"information","number":"1","alias":"information"},{"id":"2","title":"entertainments","number":"2","alias":"entertainments"}],"text":""}') 
 

 
>>> for data in field['js']: 
 
...  print data['title'] 
 
... 
 

 
information 
 
entertainments

+1

[我如何对Python中的字符串列表进行排序?](http://stackoverflow.com/questions/36139/how-do-i-sort-a-list-of-strings-in-python ) – redFIVE

+0

没有工作,但将再次尝试 – cann0nextr3me

+0

谷歌绝对作品,我可以向你保证。 – redFIVE

回答

0

的一种方式:

>>> for data in sorted(field['js']): 
... print data['title'] 
... 
entertainments 
information 
+0

中的方法可能会添加一些关于'sorted'的信息? –