How to parse(get) the cities array which is in object?
-
{"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"]}]}
-
{"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"]}]}
@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 Pythonjsonmodule. -
@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
-
@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
@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
datalevel? For cities did you try similar likeQJsonArray cities = jsonObject.value("cities").toArray(); qDebug() << cities.size() << cities[0]; -
@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
datalevel? For cities did you try similar likeQJsonArray cities = jsonObject.value("cities").toArray(); qDebug() << cities.size() << cities[0];