我是Talend的初学者。 我尝试创建一个新作业,我通过tREST组件读取JSON数据。然后我想提取数据以插入MySql数据库。
我的组件tREST以JSON格式给出了以下数据(在jsonlint上验证)
{
"expand": "names,schema",
"startAt": 0,
"maxResults": 50,
"total": 1,
"issues": [
{
"expand": "editmeta,renderedFields,transitions,changelog,operations",
"id": "97777",
"self": "https://issuetracker.aaaaa.com/jira/rest/api/2/issue/97777",
"key": "MMMMMM-888",
"fields": {
"progress": {
"progress": 7200,
"total": 7200,
"percent": 100
},
"summary": "Generate package for 88888888 1.0.3",
"customfield_10083": "1_*:*_1_*:*_363000_*|*_10000_*:*_1_*:*_10000_*|*_5_*:*_1_*:*_0",
"customfield_10082": null,
"customfield_10360": null,
"issuetype": {
"self": "https://issuetracker.aaaaa.com/jira/rest/api/2/issuetype/3",
"id": "3",
"description": "A task that needs to be done.",
"iconUrl": "https://issuetracker.aaaaa.com/jira/images/icons/issuetypes/task.png",
"name": "Task",
"subtask": false
},
"customfield_10110": null,
"customfield_10260": null,
"customfield_10261": null,
"resolution": {
"self": "https://issuetracker.aaaaa.com/jira/rest/api/2/resolution/1",
"id": "1",
"description": "A fix for this issue is checked into the tree and tested.",
"name": "Fixed"
},
"fixVersions": [],
"resolutiondate": "2014-12-05T17:24:01.000+0100",
"timespent": 7200,
"reporter": {
"self": "https://issuetracker.aaaaa.com/jira/rest/api/2/user?username=ext_aaaaaa_dupont",
"name": "ext_aaaaaa_dupont",
"emailAddress": "jpdupont@aaaaaa.fr ",
"avatarUrls": {
"16x16": "https://issuetracker.aaaaa.com/jira/secure/useravatar?size=small&avatarId=10122",
"48x48": "https://issuetracker.aaaaa.com/jira/secure/useravatar?avatarId=10122"
},
"displayName": "Jean-Philippe Dupont",
"active": true
},
"aggregatetimeoriginalestimate": null,
"updated": "2014-12-05T17:24:01.000+0100",
"created": "2014-12-05T17:17:48.000+0100",
"description": null,
"priority": {
"self": "https://issuetracker.aaaaa.com/jira/rest/api/2/priority/7",
"iconUrl": "https://issuetracker.aaaaa.com/jira/images/icons/priority_normal.gif",
"name": "Normal",
"id": "7"
},
"customfield_10120": null,
"duedate": null,
"issuelinks": [],
"watches": {
"self": "https://issuetracker.aaaaa.com/jira/rest/api/2/issue/MMMMMM-815/watchers",
"watchCount": 0,
"isWatching": false
},
"customfield_10101": "0",
"subtasks": [],
"customfield_10100": null,
"status": {
"self": "https://issuetracker.aaaaa.com/jira/rest/api/2/status/5",
"description": "A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.",
"iconUrl": "https://issuetracker.aaaaa.com/jira/images/icons/statuses/resolved.png",
"name": "Resolved",
"id": "5"
},
"customfield_10090": {
"self": "https://issuetracker.aaaaa.com/jira/rest/api/2/customFieldOption/10071",
"value": "Maintenance",
"id": "10071"
},
"labels": [],
"workratio": -1,
"assignee": {
"self": "https://issuetracker.aaaaa.com/jira/rest/api/2/user?username=ext_aaaaaa_dupont",
"name": "ext_aaaaaa_dupont",
"emailAddress": "jpdupont@aaaaaa.fr ",
"avatarUrls": {
"16x16": "https://issuetracker.aaaaa.com/jira/secure/useravatar?size=small&avatarId=10122",
"48x48": "https://issuetracker.aaaaa.com/jira/secure/useravatar?avatarId=10122"
},
"displayName": "Jean-Philippe Dupont",
"active": true
},
"aggregatetimeestimate": 0,
"project": {
"self": "https://issuetracker.aaaaa.com/jira/rest/api/2/project/MMMMMM",
"id": "10865",
"key": "MMMMMM",
"name": "Third Part Maintenance",
"avatarUrls": {
"16x16": "https://issuetracker.aaaaa.com/jira/secure/projectavatar?size=small&pid=10865&avatarId=10299",
"48x48": "https://issuetracker.aaaaa.com/jira/secure/projectavatar?pid=10865&avatarId=10299"
}
},
"versions": [],
"customfield_10170": null,
"environment": null,
"timeestimate": 0,
"aggregateprogress": {
"progress": 7200,
"total": 7200,
"percent": 100
},
"lastViewed": null,
"customfield_10464": null,
"customfield_10463": null,
"components": [],
"customfield_10462": null,
"timeoriginalestimate": null,
"customfield_10461": null,
"customfield_10460": null,
"aggregatetimespent": 7200
}
}
]
}
我在tExtractJSONFields
组件上收到以下错误:
文档第1行出错:Le contenudesélémentsdoitinclure un balisage oudescaractèresauformat格式正确。嵌套例外:Le contenudesélémentsdoitinclure un balisage oudescaractèresauformat格式正确。
使用以下设置:
JSON Field : Body
Loop XPath Query : "/issues"
Mapping | Column | XPath query
| id | "./id"
我没有看到我的设置有什么问题......
答案 0 :(得分:1)
"16x16": "https://issuetracker.aaaaa.com/jira/secure/projectavatar?size=small&pid=10865&avatarId=10299",
"48x48": "https://issuetracker.aaaaa.com/jira/secure/projectavatar?pid=10865&avatarId=10299"
}
有些地方会出现“16x16”和“48x48”。这些标签在json中可能有效,但在xml中不起作用,并且在talend中工作的方式,json将首先转换为xml然后提取。然后,这些标签在xml格式中被视为无效并导致问题。
答案 1 :(得分:0)
请在下面找到TalendForge的JIRA链接 tExtractJsonFields can't process Unicode
当遇到无效的xml字符时,tExtractJsonFields如何解析Json有一个问题。他们在5.6.2版本中提供了json-path,这可以用来代替Xpath或者你可以在Talend中使用自定义java代码。这是堆栈溢出Json Parsing using custom routine in talend
的链接答案 2 :(得分:0)
检查输入行是否具有“正文”作为JSON字段
将“循环Xpath查询”更改为“ / issues [*]”
在tREST组件之后添加一个tLogRow组件并仅过滤主体,即阻止由tREST组件生成和添加的ERROR_CODE。