如何更新这些嵌套字典对象的值?
How Can I update the value of these nested dict object?
我正在尝试更新字典值中 all_friends_paginating_after_cursor 的值,我尝试了不同的方法但没有成功,我该如何更新该值?
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"}
"variables"
(包含 "all_friends_paginating_after_cursor"
)似乎是一个 JSON 字符串。一种可能的方法是将其转换为字典,更改值,然后再次将其转换为字符串。查看此代码片段:
import json
variables = json.loads(a["variables"])
variables["all_friends_paginating_after_cursor"] = "NEW VALUE"
a["variables"] = json.dumps(variables)
我正在尝试更新字典值中 all_friends_paginating_after_cursor 的值,我尝试了不同的方法但没有成功,我该如何更新该值?
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"}
"variables"
(包含 "all_friends_paginating_after_cursor"
)似乎是一个 JSON 字符串。一种可能的方法是将其转换为字典,更改值,然后再次将其转换为字符串。查看此代码片段:
import json
variables = json.loads(a["variables"])
variables["all_friends_paginating_after_cursor"] = "NEW VALUE"
a["variables"] = json.dumps(variables)