我已将值存储到变量中。以下是 -
itemID = item['witId']
print "new ID is :" +str(itemID)
现在我想将itemId的值传递到以下字典中:
data = '{"witIds": ["itemID "], "widgetExpiryDate":"12.06.2015 09:12:00.UTC" , "firstAlertDate":"11.06.2015 04:06:00.UTC","secondAlertDate":"11.06.2015 05:02:00.UTC" }'
此代码显示itemID
无效。
答案 0 :(得分:1)
我认为这就是你想要的:
itemID = item["witId"]
data = {"widgetExpiryDate":"12.06.2015 09:12:00.UTC" , "firstAlertDate":"11.06.2015 04:06:00.UTC","secondAlertDate":"11.06.2015 05:02:00.UTC"}
data["witIds"] = [itemID]
如果您尝试将该JSON转换为字典,则可以使用json
模块:
import json
data = '{"widgetExpiryDate":"12.06.2015 09:12:00.UTC" , "firstAlertDate":"11.06.2015 04:06:00.UTC","secondAlertDate":"11.06.2015 05:02:00.UTC" }'
json.loads(data)