【问题标题】:How Can I update the value of these nested dict object?如何更新这些嵌套 dict 对象的值?
【发布时间】:2021-05-22 17:01:44
【问题描述】:

我试图更新 dict 值中 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"}

【问题讨论】:

    标签: python json dictionary multidimensional-array facebook-app-requests


    【解决方案1】:

    看来"variables"(其中包含"all_friends_paginating_after_cursor")是一个JSON 字符串。一种可能的方法是将其转换为字典,更改值,然后再次将其转换为字符串。看看这段代码sn-p:

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

    【讨论】:

      猜你喜欢
      • 2021-09-12
      • 2017-09-22
      • 2015-06-25
      • 2021-01-23
      • 1970-01-01
      • 2021-11-27
      • 2018-11-07
      • 2017-02-27
      • 1970-01-01
      相关资源
      最近更新 更多