You need to enable JavaScript to run this app. SendGrid导出联系人返回压缩数据无法转换为自定义类问题处理
优惠活动
大模型
产品
解决方案
定价
更多

SendGrid导出联系人返回压缩数据无法转换为自定义类问题处理

处理SendGrid marketing/contacts/exports/{id} 接口返回数据的问题

我尝试处理调用marketing/contacts/exports/{id}接口返回的URL,使用了如下代码,但返回的dataresponse是压缩/加密格式:

SendGridClient client = new SendGridClient(AppConfig.ReadSetting("SENDGRID_API_KEY"));

SingleSendContactList allListsSingleSend = new SingleSendContactList();
var response = await client.RequestAsync(method: SendGridClient.Method.GET, urlPath: "marketing/lists?page_size=500");
allListsSingleSend = JsonConvert.DeserializeObject<SingleSendContactList>(response.Body.ReadAsStringAsync().Result);

SingleSendExportSetup SSExportSetup = new SingleSendExportSetup();
SSExportSetup.file_type = "json";
SSExportSetup.max_file_size = 5000;

// marketing/contacts/exports, POST returns JSON with id as main field
SingleSendExportID ExportContactsSingleSend = new SingleSendExportID();
response = await client.RequestAsync(method: SendGridClient.Method.POST, urlPath: "marketing/contacts/exports", requestBody: JsonConvert.SerializeObject(SSExportSetup));
ExportContactsSingleSend = JsonConvert.DeserializeObject<SingleSendExportID>(response.Body.ReadAsStringAsync().Result);

//Use this id to then call
// marketing/contacts/exports/id, GET returns JSON with urls as a property, use urls[0]
SingleSendExportURL ExportURLSingleSend = new SingleSendExportURL();
response = await client.RequestAsync(method: SendGridClient.Method.GET, urlPath: "marketing/contacts/exports/" + ExportContactsSingleSend.id);
ExportURLSingleSend = JsonConvert.DeserializeObject<SingleSendExportURL>(response.Body.ReadAsStringAsync().Result);

// Call the URL to get the returned JSON
List<SingleSendExportData> ExportDataSingleSend = new List<SingleSendExportData>();
var dataresponse = await client.RequestAsync(method: SendGridClient.Method.GET, urlPath: ExportURLSingleSend.urls[0]);
ExportDataSingleSend = JsonConvert.DeserializeObject<List<SingleSendExportData>>(dataresponse.Body.ReadAsStringAsync().Result);

我将ExportURLSingleSend.urls[0]中的URL粘贴到浏览器可以正常触发文件下载,数据完整。请问我如何才能将该数据转换为List<SingleSendExportData>类对象?
我已向SendGrid官方支持提交该问题,对方引导我来此咨询,感谢。

更新1

我已解决压缩数据问题,但随后发现SendGrid返回的JSON格式不规范,数据行之间没有逗号分隔。

更新2

我已解决行分隔JSON文件的处理问题,目前我已可以无需保存文件直接读取压缩JSON文件,处理完JSON格式后即可加载到List<SingleSendExportData>列表中。

内容的提问来源于stack exchange,提问作者Joel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.19 22:27:04