我想在数据
下面追加jsonmeta = [{
"output_metadata": {
"api_URL": apiURL,
"query_execution_time": queryExecTime,
"api_execution_time": apiExecTime,
}
}]
jsondata = json.dumps([dict(ix) for ix in Data], default=str)
json数据:
{"data": [{"id": "1234", "name": "jhon", "dept": "APA"}]}
meta.append(jsondata)
预期结果:
{"output_metadata": {"api_url": "xxxxx", "query_execution_time":"xxxxx", "api_execution_time":"xxxxx"}},{"data": "[{"id": "1234", "name": "jhon", "dept": "APA"}]}
输出:
{"output_metadata": {"api_url": "XXXXXX", "query_execution_time": "XXXXXX", "api_execution_time":"XXXXXX" }},{"data": "[{"\id": "1234\", "\name": "\jhon", "\dept": "\APA"}]}
如何从最终输出中删除\?
答案 0 :(得分:1)
如果你上面写的这个东西是python你创建的元变量是无效的,因为在每个"你应该使用一个转义字符,每次你进入一个新的行。例如,你应该写:
data = [{"id": 1234, "name": "jhon", "dept": "APA" }]
jdata= json.dumps([dict(ix) for ix in data], default=str)
apiURL = 'url'
queryExecTime = 1
apiExecTime = 1
meta = [{ "output_metadata": { "api_url": apiURL,
"query_execution_time": queryExecTime,
"api_execution_time": apiExecTime, } }]
jdata = { "data": jdata }
meta.append(jdata)
res = json.dumps(meta)
print(res)
将json作为字符串处理,然后将它们附加到一个列表中。这是你想要的吗?
编辑:如果您运行类似
的内容 '[{"output_metadata": {"api_url": "url", "query_execution_time": 1, "api_execution_time": 1}}, {"data": "[{\\"id\\": 1234, \\"name\\": \\"jhon\\", \\"dept\\": \\"APA\\"}]"}]'
结果将是:
<textarea id="html" name="html">textarea 1</textarea>
<input type="button" value="Copy 1" onclick="copy_to_clipboard('html');"><br><br><br>
<textarea id="test" name="htmltest">textarea 2</textarea>
<input type="button" value="Copy 2" onclick="copy_to_clipboard('test');">
<script>
function copy_to_clipboard(html)
{
document.getElementById(html).select();
document.execCommand('copy');
}
</script>
\用作&#34;的转义字符。您将结果视为文字字符串。