json パースでTypeError: string indices must be integers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.filepath = self._get_value_from_messageattributes("filepath") | |
File "/xxxxxx/test.py", line 93, in _get_value_from_messageattributes | |
self.logger.debug("return value : %s", self.message["Message"][key]["Value"]) | |
TypeError: string indices must be integers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Subject" : "testtesttest", | |
"Message" : { | |
"filepath" : {"Value":"/xxxxxx/hogehogehoge.txt"} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
def _get_value_from_messageattributes(self, key): | |
# 一回読み込んで.... | |
self.message = json.loads(message) | |
""" | |
"Message"以下が単なるStringになってたので下記はエラー | |
self.logger.debug("return value : %s", self.message["Message"][key]["Value"]) | |
""" | |
# "Message"配下のStringを再度json形式で読み込む | |
msg_json = json.loads(self.message["Message"]) | |
self.logger.debug("return value : %s", msg_json[key]["Value"]) | |
return msg_json[key]["Value"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment