简体   繁体   中英

How Can I update the value of these nested dict object?

I was trying to update the value of all_friends_paginating_after_cursor in the dict values, I tried deferent ways but didn't work how can I update the value?

a= {"doc_id": "1", "method": "post", "locale": "user", "pretty": "false", "format": "json", "purpose": "fetch", "fb_api_client_context": "{\"load_next_page_counter\":1,\"client_connection_size\":20}", "variables": "{\"profile_id\":\"1\",\"profile_image_size\":180,\"all_friends_paginating_first\":20,\"all_friends_paginating_at_stream_use_customized_batch\":false,\"all_friends_paginating_after_cursor\":\"AQHR4waNWT-YvaXk-AXhRmdl2ldevUdzx_TybGh2ggSielOYRQc-jOZsdsffdsfdsfdsfds1_g\"}", "fb_api_req_friendly_name": "AllFriendListContentQuery", "fb_api_caller_class": "ConnectionManager", "fb_api_analytics_tags": "[\"GraphServices\",\"At_Connection\"]", "client_trace_id": "jj89u654654465", "server_timestamps": "true"}

It appears that "variables" (which contains "all_friends_paginating_after_cursor" ) is a JSON string. One possible way you could do this is convert it into a dict, change the value, then convert it to a string again. Check out this code snippet:

import json
variables = json.loads(a["variables"])
variables["all_friends_paginating_after_cursor"] = "NEW VALUE"
a["variables"] = json.dumps(variables)

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