Guest User

Untitled

a guest
Feb 25th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. response = {
  2. "data": [
  3. {
  4. "type": "functionalNames",
  5. "id": "1",
  6. "attributes": {
  7. "id": "1",
  8. "title": "MDHearingAid"
  9. },
  10. "links": [
  11.  
  12. ],
  13. "relationships": [
  14.  
  15. ]
  16. },
  17. {
  18. "type": "functionalNames",
  19. "id": "2",
  20. "attributes": {
  21. "id": "2",
  22. "title": "Hearing aid"
  23. },
  24. "links": [
  25.  
  26. ],
  27. "relationships": [
  28.  
  29. ]
  30. },
  31. {
  32. "type": "functionalNames",
  33. "id": "47",
  34. "attributes": {
  35. "id": "47",
  36. "title": "Batteries"
  37. },
  38. "links": [
  39.  
  40. ],
  41. "relationships": [
  42.  
  43. ]
  44. },
  45. {
  46. "type": "functionalNames",
  47. "id": "49",
  48. "attributes": {
  49. "id": "49",
  50. "title": "UV Clean and Dry Box"
  51. },
  52. "links": [
  53.  
  54. ],
  55. "relationships": [
  56.  
  57. ]
  58. },
  59. {
  60. "type": "functionalNames",
  61. "id": "50",
  62. "attributes": {
  63. "id": "50",
  64. "title": "Hearing Aid Air Blower"
  65. },
  66. "links": [
  67.  
  68. ],
  69. "relationships": [
  70.  
  71. ]
  72. }
  73. ],
  74. "limit": 5,
  75. "offset": 0,
  76. "included": [
  77.  
  78. ],
  79. "success": True,
  80. "error": {
  81.  
  82. },
  83. "ver": 1,
  84. "service": "MS_PRODUCT"
  85. }
  86.  
  87.  
  88. list_Data = response['data']
  89.  
  90. # Get data from dictionary (Old)
  91. list_IDs = [None]*len(list_Data)
  92. list_Title = [None]*len(list_Data)
  93.  
  94. for index in range(0, len(list_Data)):
  95. data = list_Data[index]
  96. attributes = data['attributes']
  97.  
  98. list_IDs[index] = int(attributes['id'])
  99. list_Title[index] = str(attributes['title'])
  100.  
  101.  
  102. # Get data from dictionary (New)
  103. ids = []
  104. titles = []
  105.  
  106. for item in response['data']:
  107. ids.append(int(item['attributes']['id']))
  108. titles.append(str(item['attributes']['title']))
  109.  
  110. print(ids)
  111. print(titles)
Add Comment
Please, Sign In to add comment