Читать JSON вложенных коллекций - PullRequest
0 голосов
/ 03 апреля 2020

Я сохранил JSON ответ в файле, и я использовал эту функцию

Public Function FileToString(sourceFile As String) As String
Dim s           As String
Dim i           As Integer

i = FreeFile
Open sourceFile For Input As #i
s = Input(LOF(i), i)
Close #i

FileToString = s
End Function

И в коде я получил JSON вот так

    v = FileToString(ThisWorkbook.Path & "\Sample.json")

  Set json = JSONConverter.ParseJson(v)

Вот JSON пример

{
  "R": {
    "has_menu_status": {
      "delivery": -1,
      "takeaway": -1
    },
    "res_id": 16577491
  },
  "apikey": "3f23dfbf4144fcff211a629acee15b40",
  "id": "16577491",
  "name": "Chicken on Lygon",
  "url": "https://www.zomato.com/melbourne/chicken-on-lygon-brunswick?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1",
  "location": {
    "address": "61 Lygon Street, Brunswick, Melbourne",
    "locality": "Brunswick",
    "city": "Melbourne",
    "city_id": 259,
    "latitude": "-37.7773694845",
    "longitude": "144.9707026407",
    "zipcode": "3057",
    "country_id": 14,
    "locality_verbose": "Brunswick, Melbourne"
  },
  "switch_to_order_menu": 0,
  "cuisines": "Charcoal Chicken",
  "timings": "9 AM to 9 PM",
  "average_cost_for_two": 35,
  "price_range": 2,
  "currency": "$",
  "highlights": [
    "Dinner",
    "Lunch",
    "Debit Card",
    "Credit Card",
    "Cash",
    "Takeaway Available",
    "Smoking Area",
    "Table booking recommended",
    "Indoor Seating",
    "Outdoor Seating"
  ],
  "offers": [],
  "opentable_support": 0,
  "is_zomato_book_res": 0,
  "mezzo_provider": "OTHER",
  "is_book_form_web_view": 0,
  "book_form_web_view_url": "",
  "book_again_url": "",
  "thumb": "https://b.zmtcdn.com/data/pictures/chains/1/16577491/f4109e833226ebaace7934b0c397a2e0.jpg?fit=around%7C200%3A200&crop=200%3A200%3B%2A%2C%2A",
  "user_rating": {
    "aggregate_rating": "4.0",
    "rating_text": "Very Good",
    "rating_color": "5BA829",
    "rating_obj": {
      "title": {
        "text": "4.0"
      },
      "bg_color": {
        "type": "lime",
        "tint": "600"
      }
    },
    "votes": "92"
  },
  "all_reviews_count": 37,
  "photos_url": "https://www.zomato.com/melbourne/chicken-on-lygon-brunswick/photos?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1#tabtop",
  "photo_count": 36,
  "photos": [
    {
      "photo": {
        "id": "u_MjIyMjk5NTQwOD",
        "url": "https://b.zmtcdn.com/data/reviews_photos/bab/497c70677e930f2a8e95af813b664bab_1472439938.jpg?fit=around%7C640%3A640&crop=640%3A640%3B%2A%2C%2A",
        "thumb_url": "https://b.zmtcdn.com/data/reviews_photos/bab/497c70677e930f2a8e95af813b664bab_1472439938.jpg?impolicy=newcropandfit&cropw=900&croph=900&cropoffsetx=98&cropoffsety=0&cropgravity=NorthWest&fitw=200&fith=200&fittype=ignore",
        "user": {
          "name": "Penguineats",
          "zomato_handle": "penguineats",
          "foodie_level": "Connoisseur",
          "foodie_level_num": 13,
          "foodie_color": "e95151",
          "profile_url": "https://www.zomato.com/penguineats?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1",
          "profile_image": "https://b.zmtcdn.com/data/user_profile_pictures/692/09c3d05682f3308ed0f5299c891f4692.jpg?fit=around%7C100%3A100&crop=100%3A100%3B%2A%2C%2A",
          "profile_deeplink": "zomato://u/24127490"
        },
        "res_id": 16577491,
        "caption": "",
        "timestamp": 1472439975,
        "friendly_time": "Aug 29, 2016",
        "width": 640,
        "height": 640
      }
    },
    {
      "photo": {
        "id": "u_Mzg0NTY1MDAxMz",
        "url": "https://b.zmtcdn.com/data/reviews_photos/541/f0b68acf28bef89d9158b6a9c6ad3541_1472439940.jpg?fit=around%7C640%3A640&crop=640%3A640%3B%2A%2C%2A",
        "thumb_url": "https://b.zmtcdn.com/data/reviews_photos/541/f0b68acf28bef89d9158b6a9c6ad3541_1472439940.jpg?impolicy=newcropandfit&cropw=1200&croph=1200&cropoffsetx=14&cropoffsety=0&cropgravity=NorthWest&fitw=200&fith=200&fittype=ignore",
        "user": {
          "name": "Penguineats",
          "zomato_handle": "penguineats",
          "foodie_level": "Connoisseur",
          "foodie_level_num": 13,
          "foodie_color": "e95151",
          "profile_url": "https://www.zomato.com/penguineats?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1",
          "profile_image": "https://b.zmtcdn.com/data/user_profile_pictures/692/09c3d05682f3308ed0f5299c891f4692.jpg?fit=around%7C100%3A100&crop=100%3A100%3B%2A%2C%2A",
          "profile_deeplink": "zomato://u/24127490"
        },
        "res_id": 16577491,
        "caption": "",
        "timestamp": 1472439975,
        "friendly_time": "Aug 29, 2016",
        "width": 640,
        "height": 640
      }
    },
    {
      "photo": {
        "id": "u_NzQyODE1MDkyMT",
        "url": "https://b.zmtcdn.com/data/reviews_photos/54f/347ceb4cfdcc03f04ced2aa116d8c54f_1472439936.jpg?fit=around%7C640%3A640&crop=640%3A640%3B%2A%2C%2A",
        "thumb_url": "https://b.zmtcdn.com/data/reviews_photos/54f/347ceb4cfdcc03f04ced2aa116d8c54f_1472439936.jpg?impolicy=newcropandfit&cropw=900&croph=900&cropoffsetx=300&cropoffsety=0&cropgravity=NorthWest&fitw=200&fith=200&fittype=ignore",
        "user": {
          "name": "Penguineats",
          "zomato_handle": "penguineats",
          "foodie_level": "Connoisseur",
          "foodie_level_num": 13,
          "foodie_color": "e95151",
          "profile_url": "https://www.zomato.com/penguineats?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1",
          "profile_image": "https://b.zmtcdn.com/data/user_profile_pictures/692/09c3d05682f3308ed0f5299c891f4692.jpg?fit=around%7C100%3A100&crop=100%3A100%3B%2A%2C%2A",
          "profile_deeplink": "zomato://u/24127490"
        },
        "res_id": 16577491,
        "caption": "",
        "timestamp": 1472439975,
        "friendly_time": "Aug 29, 2016",
        "width": 640,
        "height": 640
      }
    },
    {
      "photo": {
        "id": "u_NzQ5MzQwMTgzNT",
        "url": "https://b.zmtcdn.com/data/reviews_photos/940/cd9843bdcdfe2b75cffedf7ebdfff940_1472439918.jpg?fit=around%7C640%3A640&crop=640%3A640%3B%2A%2C%2A",
        "thumb_url": "https://b.zmtcdn.com/data/reviews_photos/940/cd9843bdcdfe2b75cffedf7ebdfff940_1472439918.jpg?impolicy=newcropandfit&cropw=1200&croph=1200&cropoffsetx=0&cropoffsety=320&cropgravity=NorthWest&fitw=200&fith=200&fittype=ignore",
        "user": {
          "name": "Penguineats",
          "zomato_handle": "penguineats",
          "foodie_level": "Connoisseur",
          "foodie_level_num": 13,
          "foodie_color": "e95151",
          "profile_url": "https://www.zomato.com/penguineats?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1",
          "profile_image": "https://b.zmtcdn.com/data/user_profile_pictures/692/09c3d05682f3308ed0f5299c891f4692.jpg?fit=around%7C100%3A100&crop=100%3A100%3B%2A%2C%2A",
          "profile_deeplink": "zomato://u/24127490"
        },
        "res_id": 16577491,
        "caption": "",
        "timestamp": 1472439975,
        "friendly_time": "Aug 29, 2016",
        "width": 640,
        "height": 640
      }
    },
    {
      "photo": {
        "id": "u_0MzIzMTI1NjM3N",
        "url": "https://b.zmtcdn.com/data/reviews_photos/573/f7fbb8e1b42346f42c044ac6570f5573_1472439930.jpg?fit=around%7C640%3A640&crop=640%3A640%3B%2A%2C%2A",
        "thumb_url": "https://b.zmtcdn.com/data/reviews_photos/573/f7fbb8e1b42346f42c044ac6570f5573_1472439930.jpg?impolicy=newcropandfit&cropw=1200&croph=1200&cropoffsetx=116&cropoffsety=0&cropgravity=NorthWest&fitw=200&fith=200&fittype=ignore",
        "user": {
          "name": "Penguineats",
          "zomato_handle": "penguineats",
          "foodie_level": "Connoisseur",
          "foodie_level_num": 13,
          "foodie_color": "e95151",
          "profile_url": "https://www.zomato.com/penguineats?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1",
          "profile_image": "https://b.zmtcdn.com/data/user_profile_pictures/692/09c3d05682f3308ed0f5299c891f4692.jpg?fit=around%7C100%3A100&crop=100%3A100%3B%2A%2C%2A",
          "profile_deeplink": "zomato://u/24127490"
        },
        "res_id": 16577491,
        "caption": "",
        "timestamp": 1472439975,
        "friendly_time": "Aug 29, 2016",
        "width": 640,
        "height": 640
      }
    },
    {
      "photo": {
        "id": "u_Mjc4MzkyOTM4OD",
        "url": "https://b.zmtcdn.com/data/reviews_photos/097/9b36b2f42b3b414a1b6bd942b5a71097_1472439931.jpg?fit=around%7C640%3A640&crop=640%3A640%3B%2A%2C%2A",
        "thumb_url": "https://b.zmtcdn.com/data/reviews_photos/097/9b36b2f42b3b414a1b6bd942b5a71097_1472439931.jpg?impolicy=newcropandfit&cropw=900&croph=900&cropoffsetx=196&cropoffsety=0&cropgravity=NorthWest&fitw=200&fith=200&fittype=ignore",
        "user": {
          "name": "Penguineats",
          "zomato_handle": "penguineats",
          "foodie_level": "Connoisseur",
          "foodie_level_num": 13,
          "foodie_color": "e95151",
          "profile_url": "https://www.zomato.com/penguineats?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1",
          "profile_image": "https://b.zmtcdn.com/data/user_profile_pictures/692/09c3d05682f3308ed0f5299c891f4692.jpg?fit=around%7C100%3A100&crop=100%3A100%3B%2A%2C%2A",
          "profile_deeplink": "zomato://u/24127490"
        },
        "res_id": 16577491,
        "caption": "",
        "timestamp": 1472439975,
        "friendly_time": "Aug 29, 2016",
        "width": 640,
        "height": 640
      }
    },
    {
      "photo": {
        "id": "u_3NDY5ODUyMTg4N",
        "url": "https://b.zmtcdn.com/data/reviews_photos/288/05b72783b4b02a141e235216d37f3288_1472439916.jpg?fit=around%7C640%3A640&crop=640%3A640%3B%2A%2C%2A",
        "thumb_url": "https://b.zmtcdn.com/data/reviews_photos/288/05b72783b4b02a141e235216d37f3288_1472439916.jpg?impolicy=newcropandfit&cropw=900&croph=900&cropoffsetx=65&cropoffsety=0&cropgravity=NorthWest&fitw=200&fith=200&fittype=ignore",
        "user": {
          "name": "Penguineats",
          "zomato_handle": "penguineats",
          "foodie_level": "Connoisseur",
          "foodie_level_num": 13,
          "foodie_color": "e95151",
          "profile_url": "https://www.zomato.com/penguineats?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1",
          "profile_image": "https://b.zmtcdn.com/data/user_profile_pictures/692/09c3d05682f3308ed0f5299c891f4692.jpg?fit=around%7C100%3A100&crop=100%3A100%3B%2A%2C%2A",
          "profile_deeplink": "zomato://u/24127490"
        },
        "res_id": 16577491,
        "caption": "",
        "timestamp": 1472439975,
        "friendly_time": "Aug 29, 2016",
        "width": 640,
        "height": 640
      }
    },
    {
      "photo": {
        "id": "u_ODE1OTYyNzQ2Mj",
        "url": "https://b.zmtcdn.com/data/reviews_photos/455/c9b1d0e116def344fddbb3e0b993e455_1472549452.jpg",
        "thumb_url": "https://b.zmtcdn.com/data/reviews_photos/455/c9b1d0e116def344fddbb3e0b993e455_1472549452.jpg?impolicy=newcropandfit&cropw=2448&croph=2448&cropoffsetx=0&cropoffsety=534&cropgravity=NorthWest&fitw=200&fith=200&fittype=ignore",
        "user": {
          "name": "Mr MM Smith",
          "zomato_handle": "the_mr_smith",
          "foodie_level": "Connoisseur",
          "foodie_level_num": 12,
          "foodie_color": "e95151",
          "profile_url": "https://www.zomato.com/the_mr_smith?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1",
          "profile_image": "https://b.zmtcdn.com/data/user_profile_pictures/2e5/8efe741cdaae6150bdd9560dd98892e5.jpg?fit=around%7C100%3A100&crop=100%3A100%3B%2A%2C%2A",
          "profile_deeplink": "zomato://u/22062307"
        },
        "res_id": 16577491,
        "caption": "",
        "timestamp": 1472549453,
        "friendly_time": "Aug 30, 2016",
        "width": 2448,
        "height": 3264
      }
    },
    {
      "photo": {
        "id": "u_MjYwOTA1MjUyMz",
        "url": "https://b.zmtcdn.com/data/reviews_photos/77f/17e1d9b7b9ccd9847a62d88dd507d77f_1472439933.jpg?fit=around%7C640%3A640&crop=640%3A640%3B%2A%2C%2A",
        "thumb_url": "https://b.zmtcdn.com/data/reviews_photos/77f/17e1d9b7b9ccd9847a62d88dd507d77f_1472439933.jpg?impolicy=newcropandfit&cropw=900&croph=900&cropoffsetx=75&cropoffsety=0&cropgravity=NorthWest&fitw=200&fith=200&fittype=ignore",
        "user": {
          "name": "Penguineats",
          "zomato_handle": "penguineats",
          "foodie_level": "Connoisseur",
          "foodie_level_num": 13,
          "foodie_color": "e95151",
          "profile_url": "https://www.zomato.com/penguineats?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1",
          "profile_image": "https://b.zmtcdn.com/data/user_profile_pictures/692/09c3d05682f3308ed0f5299c891f4692.jpg?fit=around%7C100%3A100&crop=100%3A100%3B%2A%2C%2A",
          "profile_deeplink": "zomato://u/24127490"
        },
        "res_id": 16577491,
        "caption": "",
        "timestamp": 1472439975,
        "friendly_time": "Aug 29, 2016",
        "width": 640,
        "height": 640
      }
    },
    {
      "photo": {
        "id": "u_k3OTMyODUzODQ4",
        "url": "https://b.zmtcdn.com/data/reviews_photos/9d0/fc56d1aed12306a9cab2fafff630f9d0_1475997888.jpg",
        "thumb_url": "https://b.zmtcdn.com/data/reviews_photos/9d0/fc56d1aed12306a9cab2fafff630f9d0_1475997888.jpg?impolicy=newcropandfit&cropw=747&croph=747&cropoffsetx=0&cropoffsety=155&cropgravity=NorthWest&fitw=200&fith=200&fittype=ignore",
        "user": {
          "name": "Ed Edwards",
          "foodie_level": "Foodie",
          "foodie_level_num": 3,
          "foodie_color": "ffd35d",
          "profile_url": "https://www.zomato.com/users/ed-edwards-36226009?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1",
          "profile_image": "https://b.zmtcdn.com/data/user_profile_pictures/cb6/4865d7a74db0f167038c4be0e8faccb6.jpg?fit=around%7C100%3A100&crop=100%3A100%3B%2A%2C%2A",
          "profile_deeplink": "zomato://u/36226009"
        },
        "res_id": 16577491,
        "caption": "the size was ample.. ",
        "timestamp": 1475997888,
        "friendly_time": "Oct 09, 2016",
        "width": 747,
        "height": 1328
      }
    }
  ],
  "menu_url": "https://www.zomato.com/melbourne/chicken-on-lygon-brunswick/menu?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1&openSwipeBox=menu&showMinimal=1#tabtop",
  "featured_image": "https://b.zmtcdn.com/data/pictures/chains/1/16577491/f4109e833226ebaace7934b0c397a2e0.jpg",
  "has_online_delivery": 0,
  "is_delivering_now": 0,
  "store_type": "",
  "include_bogo_offers": true,
  "deeplink": "zomato://restaurant/16577491",
  "is_table_reservation_supported": 0,
  "has_table_booking": 0,
  "events_url": "https://www.zomato.com/melbourne/chicken-on-lygon-brunswick/events#tabtop?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1",
  "phone_numbers": "03 9078 5541",
  "all_reviews": {
    "reviews": [
      {
        "review": [
          "Good Review",
          "Perfect"
        ]
      },
      {
        "review": [
          "Very Good"
        ]
      },
      {
        "review": [
          "Yes Good",
          "Great",
          "Awesome"
        ]
      },
      {
        "review": []
      },
      {
        "review": []
      }
    ]
  },
  "establishment": [
    "Fast Food"
  ]
}

В листе я собираюсь поместить пять столбцов для коллекции all_reviews. Иногда вообще нет отзывов, а иногда больше 5, но я придерживаюсь 5 Как в примере:

в первом столбце должна быть строка >> Good Review & vbcrlf & Perfect (так как они два, так что результат будет в две строки в одной и той же ячейке)

во втором столбце должна быть строка >> Очень хорошо

трижды должно быть >> Да Хорошо & vbcrlf & Хорошо & vbcrlf & Awesome

четвертый будет пустым, а также пятый

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...