首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Oracle数据迁移及XML到JSon的转换

Oracle数据迁移及XML到JSon的转换
EN

Stack Overflow用户
提问于 2018-08-31 06:11:40
回答 1查看 112关注 0票数 1

Azure Data Factory能否将字符串从Oracle (一种可扩展标记语言)转换为JSon对象,以作为对象保存在Cosmos的集合中?我试过了,但我在Cosmos DB中只得到了一个字符串(json对象)作为一个简单的属性。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-31 10:19:38

根据我的经验,azure数据工厂可以传输数据,但不会帮助您完成一些序列化步骤。所以,你的数据存储在宇宙数据库中,就像"info": "{\"Id\":\"1\",\"Name\":\"AA\",\"Address\":\"HQ - Main Line\"}"一样。

要处理此解决方案,我建议您使用Azure Function Cosmos DB Trigger。请参考我的代码:

using System;
using System.Collections.Generic;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Newtonsoft.Json.Linq;

namespace ProcessJson
{
    public class Class1
    {
        [FunctionName("DocumentUpdates")]
        public static void Run(
        [CosmosDBTrigger(databaseName:"db",collectionName: "item", ConnectionStringSetting = "CosmosDBConnection",LeaseCollectionName = "leases",
            CreateLeaseCollectionIfNotExists = true)]
        IReadOnlyList<Document> documents,
        TraceWriter log)
        {
            log.Verbose("Start.........");
            String endpointUrl = "https://***.documents.azure.com:443/";
            String authorizationKey = "***";
            String databaseId = "db";
            String collectionId = "import";

            DocumentClient client = new DocumentClient(new Uri(endpointUrl), authorizationKey);

            for (int i = 0; i < documents.Count; i++)
            {
                Document doc = documents[i];
                String info = doc.GetPropertyValue<String>("info");
                JObject o = JObject.Parse(info);

                doc.SetPropertyValue("info", o);

                client.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(databaseId, collectionId, doc.Id), doc);

                log.Verbose("Update document Id " + doc.Id);
            }
        }
    }
}

此外,您还可以参考我之前的案例:Azure Cosmos DB SQL - how to unescape inner json property

希望能对你有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52106028

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档