简体   繁体   中英

How to add dictionary items to jsonarray while in loop?

So I have a data structure like so...a dictionary...

         fbIds = ["him", "her", "it", "that"]

then I have a database i'm adding a json structure to...

         res =  r.table("usa_nyc_bronx_merchants").insert({

                "street_address": streetName.lower(),
                "city": cityName.lower(),
                "state": stateName.lower(),
                "zipcode": zipcodeNumber.lower(),
                "county": countyName.lower(),
                "fbIds": [ADD DICTIONARY ITEMS TO THIS ARRAY]
          .....

How do i add the items in that dictionary into that that json array...mind you all this code is already in a for loop.

Thanks!

fbIds is already an array ( list in python terms). So you should be able to just do:

res =  r.table("usa_nyc_bronx_merchants").insert({
            "street_address": streetName.lower(),
            "city": cityName.lower(),
            "state": stateName.lower(),
            "zipcode": zipcodeNumber.lower(),
            "county": countyName.lower(),
            "fbIds": fbIds
      .....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM