2015-05-16 6 views
-2

Я пытаюсь получить доступ к «id», «first_name» из json в Excel vba.Доступ к элементам из JSON

{ 
    "paging": { 
     "per_page": 10, 
     "page": 1, 
     "previous": null, 
     "self": "/api/v1/users?per_page=10&page=1", 
     "next": null 
    }, 
    "data": [ 
     { 
      "id": 15093, 
      "first_name": "ala", 
      "last_name": "adasd", 
      "display_name": "Ali Saigar", 
      "email": "[email protected]", 
      "user_type_id": 1, 
      "billable": true, 
      "hire_date": null, 
      "termination_date": null, 
      "mobile_phone": null, 
      "office_phone": null, 
      "deleted": false, 
      "deleted_at": null, 
      "account_owner": true, 
      "invitation_pending": false, 
      "user_settings": 786568, 
      "guid": "c010323e-bf44-4ed1-ac70-85858475df14", 
      "employee_number": null, 
      "billability_target": 100, 
      "billrate": -1, 
      "role": null, 
      "discipline": null, 
      "location": null, 
      "has_login": true, 
      "thumbnail": "" 
     }, 
     { 
      "id": 15094, 
      "first_name": "James", 
      "last_name": "Bond", 
      "display_name": "James Bond", 
      "email": null, 
      "user_type_id": 3, 
      "billable": true, 
      "hire_date": null, 
      "termination_date": null, 
      "mobile_phone": null, 
      "office_phone": null, 
      "deleted": false, 
      "deleted_at": null, 
      "account_owner": false, 
      "invitation_pending": false, 
      "user_settings": 0, 
      "guid": "91e6a979-1753-46a0-bae3-37cf4003e953", 
      "employee_number": null, 
      "billability_target": 100, 
      "billrate": -1, 
      "role": null, 
      "discipline": null, 
      "location": null, 
      "has_login": false, 
      "thumbnail": "" 
     } 
    ] 
} 

Может ли любой орган рассказать мне, как получить к нему доступ из vba? Я пробовал много методов, но не в состоянии сделать это успешно,

+0

возможно дубликат [? Является Там JSON парсер для VB6/VBA] (http://stackoverflow.com/ Вопросы/2782076/is-there-a-json-parser-for-vb6-vba) – Marc

+0

Я использую следующий https://github.com/VBA-tools/VBA-JSON – justanotherguy

+0

Добавьте то, что вы попробовали:) – Marc

ответ

1

В качестве альтернативы:

Sub JsonTest() 

    Dim json As String 
    Dim sc As Object 
    Dim o 

    Set sc = CreateObject("scriptcontrol") 
    sc.Language = "JScript" 

    json = Range("A1").Value 'for my testing... 

    sc.eval "var obj=(" & json & ")" 'evaluate the json 

    Debug.Print sc.eval("obj.data.length") 
    Debug.Print sc.eval("obj.data[0].id") 
    Debug.Print sc.eval("obj.data[0].email") 
    Debug.Print sc.eval("obj.data[0].guid") 

End Sub 
Смежные вопросы