如何将输出字符串转换为 Json 并检查 python 中的字段项?
How to convert output string to Json and check field item in python?
我是 Python 的初学者。我从 Azure 服务总线收到一条消息,如下面的屏幕截图和代码所示。
从服务总线接收消息的代码是:
import logging
import json
import azure.functions as func
def main(message: func.ServiceBusMessage):
message_content_type = message.content_type
message_body = message.get_body().decode("utf-8")
logging.info(message_body)
message = "MSG Received"
logging.info(message)
现在,我想将 message_body
从字符串转换为 JSON,然后检查以下条件:
If error = null and MSG_TYPE_TAG != Null
我怎样才能运行这个场景?
将字符串转换为JSON
message_body = json.loads(message_body)
现在,检查条件
if message_body['error'] == {} and message_body['MSG_TYPE_TAG'] != '':
# write your logic here
代码
import json
message_body = json.loads(message_body)
if message_body['error'] == {} and message_body['MSG_TYPE_TAG'] != '':
# write your logic here
我是 Python 的初学者。我从 Azure 服务总线收到一条消息,如下面的屏幕截图和代码所示。
从服务总线接收消息的代码是:
import logging
import json
import azure.functions as func
def main(message: func.ServiceBusMessage):
message_content_type = message.content_type
message_body = message.get_body().decode("utf-8")
logging.info(message_body)
message = "MSG Received"
logging.info(message)
现在,我想将 message_body
从字符串转换为 JSON,然后检查以下条件:
If error = null and MSG_TYPE_TAG != Null
我怎样才能运行这个场景?
将字符串转换为JSON
message_body = json.loads(message_body)
现在,检查条件
if message_body['error'] == {} and message_body['MSG_TYPE_TAG'] != '':
# write your logic here
代码
import json
message_body = json.loads(message_body)
if message_body['error'] == {} and message_body['MSG_TYPE_TAG'] != '':
# write your logic here