【问题标题】:Talend: parse JSON string to multiple outputTalend:将 JSON 字符串解析为多个输出
【发布时间】:2015-05-08 09:33:11
【问题描述】:

我知道this question,但我不认为标准组件没有解决方案。我正在使用 Talend ESB Studio 5.4。

我必须将来自 REST Web 服务的 JSON 字符串解析为多个输出,并将它们添加到数据库中。

数据库有两个表:

  • 用户(user_id、姓名、卡、card_id、积分)
  • 操作(user_id、action_id、描述、used_point)

我的 JSON 结构是这样的:

{
    "users": [
        {
            "name": "foo",
            "user_id": 1,
            "card": {
                "card_id": "AAA",
                "points": 10
            },
            "actions": [
                {
                    "action_id": 1,
                    "description": "buy",
                    "used_points": 2
                },
                {
                    "action_id": 3,
                    "description": "buy",
                    "used_points": 1
                }
            ]
        },
        {
            "name": "bar",
            "user_id": 2,
            "card": {
                "card_id": "BBB",
                "points": -1
            },
            "actions": [
                {
                    "id": 2,
                    "description": "sell",
                    "used_point": 5
                }
            ]
        }
    ]
}

我尝试添加 JSON 模式元数据,但我不清楚如何“扁平化”JSON。我曾尝试查看 tXMLMap、tExtractJSONFields .. 但到目前为止还没有运气。 我还查看了 tJavaRow,但我不明白如何为此创建 Schema。

很遗憾,因为直到现在我都喜欢 Talend!有什么建议吗?

【问题讨论】:

  • 为什么要对非平面文件进行平面化?当您创建新的 json 文件时,向导会为您检索架构。
  • 所以我需要保存 json 文件并重新加载它吗?

标签: json talend


【解决方案1】:

您可以在磁盘中保存一个 json 文件,然后在 Talend studio 的元数据中创建新的 json 文件,向导会为您检索架构,保存后,您可以在元数据的通用架构中复制架构,然后完成了,在你想要的地方使用通用模式,这是在 tRestClient 组件中使用通用模式的方法:

【讨论】:

  • 与 tRestClient 我一直在接收 没有为类找到消息正文阅读器:接口 org.dom4j.Document,ContentType:text/html。
  • @mcmc 我提到 tRestClient 只是为了向您展示如何使用通用模式,请考虑查看help center
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-16
相关资源
最近更新 更多