我已经增强了基类,因此它创建了我的项目中所有表中使用的列。但是,我想在数据库中创建表时控制列的顺序,以便该DWH_ID列是表中的第一列,而在基类中创建的所有其他列是表的最后一列。
假设我的项目定义如下:
from sqlalchemy import CHAR, Column, create_engine, DateTime, Integer, Text
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.sql import func
class Base:
__table_args__ = {'schema': 'some_schema'}
dwh_id = Column(Integer, primary_key=True, autoincrement=True, comment='Surrogate key')
dwh_date_inserted = Column(DateTime(timezone=False), default=func.now(), nullable=False, comment='Date and time when the record has been inserted')
dwh_date_updated = Column(DateTime(timezone=False), nullable=True, comment='Date and time when the record has been updated')
dwh_is_active = Column(CHAR(1), default='Y', nullable=False, comment="'Y' if the record is still available in the source, 'N' otherwise")
engine = …Run Code Online (Sandbox Code Playgroud) 我有作为 HTTP 响应收到的字符串。不幸的是,该字符串是原始格式,我无法将其转换为 JSON 对象。
示例字符串:
json_string = '{"client_id":8888,"time":null,"questions":{"id":10000,"answered":"true","answer":"The "project" was good, I enjoyed it. Do you plan to repeat it?"},"other":"When is the "project" released?"}'
Run Code Online (Sandbox Code Playgroud)
该字符串的问题在于它在某些值(用户答案)中包含双引号。可以包含双引号的值的键并不总是相同(这里“answer”和“other”在其他响应中可能不同)。用户答案可以包含任何字符(逗号、方括号、双引号...)。
我尝试使用不同的加载器(json,yaml),甚至尝试用正则表达式自己解析字符串,但总是失败。
有什么方法可以将此字符串转换为 JSON 对象吗?