Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to parse(get) the cities array which is in object?

How to parse(get) the cities array which is in object?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 469 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stephen28
    wrote on last edited by
    #1

    {"error":false,"msg":"countries and cities retrieved","data":[{"iso2":"AF","iso3":"AFG","country":"Afghanistan","cities":["Herat","Kabul","Kandahar","Molah","Rana","Shar","Sharif","Wazir Akbar Khan"]},{"iso2":"AL","iso3":"ALB","country":"Albania","cities":["Elbasan","Petran","Pogradec","Shkoder","Tirana","Ura Vajgurore"]},{"iso2":"DZ","iso3":"DZA","country":"Algeria","cities":["Algiers","Annaba","Azazga","Batna City","Blida","Bordj","Bordj Bou Arreridj","Bougara","Cheraga","Chlef","Constantine","Djelfa","Draria","El Tarf","Hussein Dey","Illizi","Jijel","Kouba","Laghouat","Oran","Ouargla","Oued Smar","Relizane","Rouiba","Saida","Souk Ahras","Tamanghasset","Tiaret","Tissemsilt","Tizi","Tizi Ouzou","Tlemcen"]}]}

    JonBJ 1 Reply Last reply
    0
    • S Stephen28

      {"error":false,"msg":"countries and cities retrieved","data":[{"iso2":"AF","iso3":"AFG","country":"Afghanistan","cities":["Herat","Kabul","Kandahar","Molah","Rana","Shar","Sharif","Wazir Akbar Khan"]},{"iso2":"AL","iso3":"ALB","country":"Albania","cities":["Elbasan","Petran","Pogradec","Shkoder","Tirana","Ura Vajgurore"]},{"iso2":"DZ","iso3":"DZA","country":"Algeria","cities":["Algiers","Annaba","Azazga","Batna City","Blida","Bordj","Bordj Bou Arreridj","Bougara","Cheraga","Chlef","Constantine","Djelfa","Draria","El Tarf","Hussein Dey","Illizi","Jijel","Kouba","Laghouat","Oran","Ouargla","Oued Smar","Relizane","Rouiba","Saida","Souk Ahras","Tamanghasset","Tiaret","Tissemsilt","Tizi","Tizi Ouzou","Tlemcen"]}]}

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Stephen28
      Is this JSON? Are you using Qt JSON support? If so look in https://doc.qt.io/qt-6/json.html. Are you using Python and want to do JSON coding from its library? If so look at Python json module.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Stephen28
        wrote on last edited by
        #3

        @Stephen28 said in How to parse(get) the cities array which is in object?:

        country

        I can parse the country but I don't know how to get the values of cities

        JonBJ 1 Reply Last reply
        0
        • S Stephen28

          @Stephen28 said in How to parse(get) the cities array which is in object?:

          country

          I can parse the country but I don't know how to get the values of cities

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Stephen28
          Would you like me to guess you are using Qt JSON classes then rather than telling me?

          You presumably already dealt with an array at the data level? For cities did you try similar like

          QJsonArray cities = jsonObject.value("cities").toArray();
          qDebug() << cities.size() << cities[0];
          
          S 1 Reply Last reply
          1
          • JonBJ JonB

            @Stephen28
            Would you like me to guess you are using Qt JSON classes then rather than telling me?

            You presumably already dealt with an array at the data level? For cities did you try similar like

            QJsonArray cities = jsonObject.value("cities").toArray();
            qDebug() << cities.size() << cities[0];
            
            S Offline
            S Offline
            Stephen28
            wrote on last edited by
            #5

            @JonB thanks bro

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved