我有一个字符串,内容如下:
my_string = '"sender" : "md-dgenie", "text" : "your dudegenie code is 6326. welcome to the world of dudegenie! your wish, my command!", "time" : "1439155575925", "name" : "John"'
我希望能从上面的字符串中构建一个字典。我尝试了一些建议,如这里所示。
split_text = my_string.split(",")
for i in split_text :
print i
然后我得到了以下输出:
"sender" : "md-dgenie"
"text" : "your dudegenie code is 6632. welcome to the world of dudegenie! your wish
my command!" ### finds "," here and splits it here too.
"time" : "1439155803426"
"name" : "p"
我希望输出一个字典的键值对,如下所示:
my_dict = { "sender" : "md-dgenie",
"text" : "your dudegenie code is 6632. welcome to the world of dudegenie! your wish, my command!",
"time" : "1439155803426",
"name" : "p" }
基本上,我想从句子中跳过“,”并构建一个字典。有任何建议都可以,非常感谢!
my_string
吗?我不知道那是否是一个有效的字符串,但是 Python 是一种奇怪的语言,可能有一些我不知道的模糊的字符串格式化方式。 - tobloefmy_string
不是字符串,也不是其他任何东西。它在语法上无效。 - Two-Bit Alchemistmy_string
上加单引号了。我已经更新了它。 - d-coder