我有一個 Azure 函式,如下所示:
public class SaveProductDataToDatabase
{
private readonly IProductRepository _productRepository;
public SaveProductDataToDatabase(IProductRepository productRepository)
{
_productRepository = productRepository;
}
[FunctionName("SaveProductDataToDatabase")]
public void Run([ServiceBusTrigger("product-data-dev-01", Connection = "ServiceBusConnectionString")] string myQueueItem, ILogger log)
{
log.LogInformation($"Processed message: {myQueueItem}");
// TODO : JSON Mapping will be added here once Service Bus Queue is Up and Running.
_productRepository.Add(new Domain.Entities.Product());
}
}
在這里,myQueueItem將回傳一個復雜的嵌套 JSON 字串
{
"metadata": {
"origin": "xyz-data",
"dateCreated": "2022-03-17T12:48:04.511Z"
},
"version": 6,
"messageId": "a44f23aa-bab4-4eed-a235-5820d966f669",
"sWrapper": {
"sid": "zzavqw18",
"identifiers": [
{
"alias": "si-sku",
"value": [
"8086300"
]
}
]
},
"itemType": "ITEM",
"master": {
"masterSource": "XYZ_PDS",
"title": {
"mainTitle": "XYZ - All Time Greats"
},
"description": {
"longDescription": "XYZ - All Time Greats",
"shortDescription": "XZY - All Time Greats"
},
"classification": {
"identifier": "1pvfy"
}
}
}
在此,我想提取sWrapper.sid、sWrapper.identifiers.value和classification.identifier屬性并將其分配給純 C# 物件。該物件將被傳遞給_productRepository.Add(<C# object goes here>);
如何處理這個映射?最好的方法是什么?請指教。
uj5u.com熱心網友回復:

PS>再次,有可能的方法......然后創建一個新類并用值填充類屬性并將物件傳遞給函式。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/465332.html
上一篇:我如何讀取這個在php中以數字作為鍵的特定json?[復制]
下一篇:處理帶有尾隨逗號的多行json
