我在json文件中使用了以下代码
"destinations": [
{
"/abc/def": {
"proxy_pass":"https://{{application_destination}}/abc/service$is_args$args",
"host": "{{application_destination}}",
}
}
]
我必须将proxy\u pass的url添加到某个变量中,然后将该变量添加到 使用python代码的代理传递
if "proxy_pass" in location_details:
proxy_pass = location_details[proxy_pass]
location_details["set"] = "$backend " + proxy_pass
location_details["proxy_pass"] = "$backend"
但我得到的输出是在代理通过后,设置值正在打印 那么,如何使用python将set值添加到json对象的开头呢
Python
dict
对象在Python 3.7之前是无序的您可以使用^{} :
输出
编辑
获得所需的订单
set
proxy_pass
host
可以使用^{} 将
host
键移动到OrderedDict
的末尾:输出
注意
也可以使用
location_details.move_to_end(key, last=False)
将key
移动到字典的开头相关问题 更多 >
编程相关推荐