我使用BuildRowSetFromJSON()来读取JSON,我发现在阅读JSON中的JSON具有挑战性,从下面的JSON中我需要的内容

g0czyy6m  于 2023-08-08  发布在  其他
关注(0)|答案(1)|浏览(96)

{“id”:“chatcmpl-7bfXu0KfUg1NaPV4CVR3BRi0eFcPT”,“object”:“chat.completion”,“created”:1689212194,“型号”:“gpt-3.5-turbo-0613”,“choices”:[{“index”:0,“消息”:{“role”:“assistant”,“content”:“\n <html>n\n感谢电子邮件\n\n <body>n\n感谢您的支持!\n尊敬的[收件人姓名]:\n我们衷心感谢您的支持与合作。您的贡献对我们的组织和事业产生了重大影响。\n感谢您的慷慨,我们得以[描述在他们的支持下取得的成就或项目]。如果没有您的帮助,这是不可能的。\n我们珍视您的持续承诺,并再次衷心感谢您相信我们的使命并选择支持我们的工作。非常感谢您的贡献。\n如果您有任何其他问题或希望了解我们的最新进展,请随时与我们联系。我们随时为您解答任何疑问。\n再次感谢您的善意和支持。\n致以诚挚的问候,【你的名字】[您的组织]\n\n\n“},“finish_reason”:“stop”}],“用法”:{“prompt_tokens”:13,“completion_tokens”:281,“total_tokens”:294
我使用了BuildRowsetFromJSON(),下面是代码
%%[ SET @json = '{“id”:“chatcmpl-7 bfXu 0 KfUg 1 NaPV 4CVR 3BRi 0 eFcPT”,“object”:“chat.completion”,“created”:1689212194,“model”:“gpt-3.5-turbo-0613”,“choices”:[{“index”:0,“message”:{“role”:“assistant”,“content”:“\n\n\n感谢您的支持!\n
亲爱的\n
我们对您的支持与合作表示衷心的感谢。您的贡献对我们的组织和事业产生了重大影响。\n
感谢您的慷慨,我们能够[描述在他们的支持下取得的成就或项目]。没有您的帮助,这是不可能的。\n
我们重视您的持续承诺,并再次衷心感谢您相信我们的使命并选择支持我们的工作。非常感谢您的贡献。\n
如果您有任何进一步的问题或想了解我们的最新进展,请随时与我们联系。我们随时为您解答任何疑问。\n
再次感谢您的善意和支持。\n
温馨的问候
[Your姓名】
[Your组织]\n\n\n“},“finish_reason”:“stop”}],“usage”:{“prompt_tokens”:13,“completion_tokens”:281,“total_tokens”:294}}'
SET @rows = BuildRowsetFromJson(@json,'$.choices[*]',0)
SET @rowcount =Rowcount(@rows)SET @row = Field(Row(@ rows,1),3)
]%%
输出:%%=v(@row)=%%
我得到的输出为- Out:停止

2ul0zpep

2ul0zpep1#

我得到了你的代码来处理以下内容:

%%[
Set @passedJSON = '{"id":"chatcmpl-7bfXu0KfUg1NaPV4CVR3BRi0eFcPT","object":"chat.completion","created":1689212194,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"message":{"role":"assistant","content":"\n\n\n Thank You Email</title>\n</head>\n\n <div style=''padding: 20px;''>\n <img src=''https://example.com/logo.png'' alt=''Logo'' style=''height: 50px;''> Thank You for Your Support!</h1>\nDear </p>\nWe would like to express our heartfelt gratitude for your support and cooperation. Your contribution has made a significant impact on our organization and our cause.</p>\nThanks to your generosity, we have been able to [describe the achievement or project made possible with their support]. Without your help, this would not have been possible.</p>\nWe value your ongoing commitment and would like to extend our sincere thanks once again for believing in our mission and choosing to support our work. Your contribution is truly appreciated.</p>\nf you have any further questions or would like to stay updated on our progress, please feel free to reach out to us. We are always here to answer any queries you may have.</p>\nOnce again, thank you for your kindness and support.</p>\nWarm regards,[Your Name][Your Organization]</p>\n </div>\n</body>\n</html>"},"finish_reason":"stop"}],"usage":{"prompt_tokens":13,"completion_tokens":281,"total_tokens":294}}'
Set @key_content = BuildRowSetFromJSON(@passedJSON, '$.choices[*].message', 1)

If RowCount(@key_content) > 0 Then
  Set @row_passedJSON = Row(@key_content, 1)
  Set @content        = Field(@row_passedJSON,'content')
Else
/*RowCount() returned 0*/
EndIf
]%%

%%=v(@content)=%%

字符串

  • 你的JSON payload的语法不正确,特别是双引号没有正确地取消。
  • BuildRowSetFromJSON函数中的JSON参数需要进入另一个级别。

相关问题