Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

can't access json proprety

I’m trying to access the ‘city’ proprety of this json but somehow it doesn’t work , this is the json struct :

"{\"ForSaleShopperPlatformFullRenderQuery{\\\"zpid\\\":28657235,\\\"platform\\\":\\\"DESKTOP_WEB\\\",\\\"formType\\\":\\\"OPAQUE\\\",\\\"contactFormRenderParameter\\\":{\\\"zpid\\\":28657235,\\\"platform\\\":\\\"desktop\\\",\\\"isDoubleScroll\\\":true},\\\"skipCFRD\\\":false,\\\"ompPlatform\\\":\\\"web\\\"}\":{\"property\":{\"listingDataSource\":\"Phoenix\",\"zpid\":28657235,\"city\":\"Boerne\",\"state\":\"TX\",\"homeStatus\":\"FOR_SALE\",\"address\":{\"streetAddress\":\"111 stone creek\",\"city\":\"Boerne\",\"state\":\"TX\",\"zipcode\":\"78006\",\"neighborhood\":null,\"community\":null,\"subdivision\":null},\"isListingClaimedByCurrentSignedInUser\":false,\"isCurrentSignedInAgentResponsible\":false,\"bedrooms\":3,\"bathrooms\":2,\"price\":345000,\"yearBuilt\":1999,\"streetAddress\":\"111 stone creek\",\"zipcode\":\"78006\",\"isCurrentSignedInUserVerifiedOwner\":false,\"propertyUpdatePageLink\":null,\"moveHomeMapLocationLink\":null,\"propertyEventLogLink\":null,\"editPropertyHistorylink\":null,\"collections\":{\"modules\":[{\"name\":\"Similar homes\",\"placement\":\"NEIGHBORHOOD\",\"propertyDetails\":[{\"miniCardPhotos\":[{\"url\":\"https://photos.zillowstatic.com/fp/219307696092bb2d5e31698cba1c1e1f-p_c.jpg\"}],\"price\":315000,\"currency\":\"USD\",\"bedrooms\":3,\"bathrooms\":3,\"livingArea\":1729,\"livingAreaValue\":1729,\"livingAreaUnits\":\"Square Feet\",\"livingAreaUnitsShort\":\"sqft\",\"listingMetadata\":{\"comminglingCategoryIsRulesApplicable\":true},\"lotSize\":2874,\"lotAreaValue\":2874.96,\"lotAreaUnits\":\"Square Feet\",\"address\":{\"streetAddress\":\"130 Hampton Bend\",\"city\":\"Boerne\",

{
    "ForSaleShopperPlatformFullRenderQuery{\"zpid\":28657235,\"platform\":\"DESKTOP_WEB\",\"formType\":\"OPAQUE\",\"contactFormRenderParameter\":{\"zpid\":28657235,\"platform\":\"desktop\",\"isDoubleScroll\":true},\"skipCFRD\":false,\"ompPlatform\":\"web\"}": {
        "property": {
            "listingDataSource": "Phoenix",
            "zpid": 28657235,
            "city": "Boerne",
            "state": "TX",
            "homeStatus": "FOR_SALE",
            "address": {
                "streetAddress": "111 stone creek",
                "city": "Boerne",
                "state": "TX",
                "zipcode": "78006",
                "neighborhood": null,
                "community": null,
                "subdivision": null
            },

this is the code :

key = 'ForSaleShopperPlatformFullRenderQuery{"zpid":28657235,"platform":"DESKTOP_WEB","formType":"OPAQUE","contactFormRenderParameter":{"zpid":28657235,"platform":"desktop","isDoubleScroll":true},"skipCFRD":false,"ompPlatform":"web"}'
        city = data["props"]["pageProps"]["componentProps"]["gdpClientCache"][key]['property']['city']

i get error :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

print(data["props"]["pageProps"]["componentProps"]["gdpClientCache"]['ForSaleShopperPlatformFullRenderQuery{\\"zpid\":28657235,\\"platform\\":\\"DESKTOP_WEB\\",\\"formType\\":\\"OPAQUE\\",\\"contactFormRenderParameter\\":{\\"zpid\\":28657235,\\"platform\\":\\"desktop\\",\\"isDoubleScroll\\":true},\\"skipCFRD\\":false,\\"ompPlatform\\":\\"web\\"}'])
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: string indices must be integers, not 'str'

tried also

key = "ForSaleShopperPlatformFullRenderQuery{\"zpid\":28657235,\"platform\":\"DESKTOP_WEB\",\"formType\":\"OPAQUE\",\"contactFormRenderParameter\":{\"zpid\":28657235,\"platform\":\"desktop\",\"isDoubleScroll\":true},\"skipCFRD\":false,\"ompPlatform\":\"web\"}"

still doesn’t work

>Solution :

First of all, your json example is not complete as I can’t see these keys.

["props"]["pageProps"]["componentProps"]["gdpClientCache"]

So I tried data[key]['property']['city'], and it works.
result

I think the problem is at this key gdpClientCache. It must have returned a string value but not the json example you showed us. That’s why the program wants you to use an integer as the index.

Double check the return value of each key and you should be able to solve the problem.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading