如何使JSON输出达到简化的正常输出?

发布于 2025-02-02 18:38:05 字数 597 浏览 3 评论 0原文

我有一个代码,可以像下面的输出一样提供输出

{
"Pdf":"July 20.pdf"
"Content":"Include any error messages"
"Page no":6
}
{
"Pdf":"July 20, 2016.pdf"
"Content":"Show what you’ve tried and tell us"
"Page no":7
}

,但是我需要输出,就像

"Pdf":"July 20.pdf", "Content":"Include any error messages", "Page no":6
"Pdf":"July 20, 2016.pdf", "Content":"Show what you’ve tried and tell us", "Page no":7

我在简化上一样。 代码吗?

results = search(query, top_k=2, index=index, model=search_model)
for result in results:
    st.write(result)

以下是任何人可以帮助我的

I have a code which gives output like below

{
"Pdf":"July 20.pdf"
"Content":"Include any error messages"
"Page no":6
}
{
"Pdf":"July 20, 2016.pdf"
"Content":"Show what you’ve tried and tell us"
"Page no":7
}

But i need output like

"Pdf":"July 20.pdf", "Content":"Include any error messages", "Page no":6
"Pdf":"July 20, 2016.pdf", "Content":"Show what you’ve tried and tell us", "Page no":7

I'm working on streamlit. Below is the code

results = search(query, top_k=2, index=index, model=search_model)
for result in results:
    st.write(result)

Can anyone help me with this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

又爬满兰若 2025-02-09 18:38:05

将其打印为字符串并更换一些字符。

代码

results = [
{
"Pdf":"July 20.pdf",
"Content":"Include any error messages",
"Page no":6
},
{
"Pdf":"July 20, 2016.pdf",
"Content":"Show what you’ve tried and tell us",
"Page no":7
}
]


for result in results:
    st.write(str(result).replace('{', '').replace('}', '').replace('\'', '\"'))

输出

"Pdf": "July 20.pdf", "Content": "Include any error messages", "Page no": 6

"Pdf": "July 20, 2016.pdf", "Content": "Show what you’ve tried and tell us", "Page no": 7

Print it as a string and replace some chars.

Code

results = [
{
"Pdf":"July 20.pdf",
"Content":"Include any error messages",
"Page no":6
},
{
"Pdf":"July 20, 2016.pdf",
"Content":"Show what you’ve tried and tell us",
"Page no":7
}
]


for result in results:
    st.write(str(result).replace('{', '').replace('}', '').replace('\'', '\"'))

Output

"Pdf": "July 20.pdf", "Content": "Include any error messages", "Page no": 6

"Pdf": "July 20, 2016.pdf", "Content": "Show what you’ve tried and tell us", "Page no": 7
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文