我的json对象是:{"values": {"empid": 20000, "empName": "Sourav", "empSal": 8200}}
但是我想删除"Values: "
。我该怎么做?我已经用Python编写了一段代码。
在后台,它从MySQL获取流式数据并发送到Kinesis
def main():
connection = {
"host": "127.0.0.1",
"port": int(sys.argv[1]),
"user": str(sys.argv[2]),
"passwd": str(sys.argv[3])}
kinesis = boto3.client("kinesis",region_name='ap-south-1')
stream = BinLogStreamReader(
connection_settings=connection,
only_events=[DeleteRowsEvent, WriteRowsEvent, UpdateRowsEvent],
server_id=100,
blocking=True,
log_file='mysql-bin.000003',
resume_stream=True,
)
for binlogevent in stream:
for row in binlogevent.rows:
print (json.dumps(row,cls=DateTimeEncoder))
kinesis.put_record(StreamName=str(sys.argv[4]), Data=json.dumps(row,cls=DateTimeEncoder),
PartitionKey="default",)
您可以调用
row['values']
,它将返回values
中的值代码中的一个示例是
如果要删除
"Values: " from the string that
json.dumps`products,只需执行替换:然后在该字符串上使用
put_record
。您的json对象是一个字典,因此您不能从中删除values:
字符串/键。如果确实删除了values
键,则对象将为空相关问题 更多 >
编程相关推荐