【发布时间】:2018-08-10 05:42:30
【问题描述】:
{
"export": {
"version": "3.4",
"date": "2018-08-09T13:19:46Z",
"groups": [
{
"name": "Templates"
}
],
"templates": [
{
"template": "Template OS",
"name": "Template OS",
"description": "",
"groups": [
{
"name": "Datawhatiwant"
}
],
这是 JSON 代码的相关部分,我想要值 datawhatiwant。
但是如果我使用print json_data["export"] 就会出现这个错误:
TypeError: string indices must be integers
那么我怎样才能获得 datawhatiwant?
【问题讨论】:
-
你的
json_data是从哪里得到的? -
您的 JSON 对象示例也不完整
-
好像你有一个字符串。您需要使用
json.loads将字符串转换为python 对象 -
@Bakuriu 我已经在使用 json.loads
-
@t0m那你可能做错了。如果您向我们提供了您正在使用的实际代码,我们可能会在 2 分钟内告诉您问题出在哪里,但我们只能根据您提供的少量信息进行猜测