2017-08-02 93 views
-1

我试图从github中获取数据与这个talend作业, enter image description here enter image description here在Talend作业中,JSONObject文本必须以<{xml version =“1.0”encoding =“UTF-8”?>的字符1处的'{'开始)

但是我无法获取数据,因为它显示了一些错误。

A JSONObject text must begin with '{' at character 1 of <?xml version="1.0" encoding="UTF-8"?> 
<root><root><id>75978949</id><name>Samplerepository</name> 

我该如何解决这个问题?

这是我的输出值,当我用浏览器测试URL时;

[ 
    { 
    "id": 59002981, 
    "name": "awesome-ciandcd", 
    "full_name": "sample/awesome-ciandcd", 
    "owner": { 
     "login": "sample", 
     "id": 354018, 
     "avatar_url": "https://avatars1.githubusercontent.com/u/354018?v=4" 

    }, 
    "private": false, 
    "html_url": "https://github.com/sample/awesome-ciandcd", 
    "description": "continuous integration and continuous delivery", 
    "fork": true, 
    "mirror_url": null, 
    "open_issues_count": 0, 
    "forks": 0, 
    "open_issues": 0, 
    "watchers": 2, 
    "default_branch": "master" 
    } 
] 

我已修改作业等,tRESTClient - > tFileOutputJSON和储值像下面,

[{"string":null,"body": 
<?xml version="1.0" encoding="UTF-8"?> 
<root> 
    <root> 
     <id>59002981</id> 
     <name>awesome-ciandcd</name> 
     <full_name>sample/awesome-ciandcd</full_name> 
     <owner> 
      <login>sample</login> 
      <id>354018</id> 
     </owner> 
     <private>false</private> 
     <fork>true</fork> 
     <forks_count>0</forks_count> 
     <default_branch>master</default_branch> 
    </root> 
    <root> 
     <id>35035177</id> 
     <name>yell-adapters-gelf</name> 
     <full_name>sample/yell-adapters-gelf</full_name> 
     <owner> 
      <login>sample</login> 
      <id>354018</id> 
     </owner> 
     <private>false</private> 
     <forks>0</forks> 
     <open_issues>0</open_issues> 
     <watchers>0</watchers> 
     <default_branch>master</default_branch> 
    </root> 
</root>,"statusCode":200}] 

在此之后,创建的作业,tFileInputJSON - > tExtractJSONFileds - > tLogRow,但抛出的错误是:无法解析JSON文件:C:/Desktop/Output.json

如何拉手T-他的问题?

+0

似乎API正在返回XML并且不是JSON。 –

+0

我试着用tXMLMap而不是tExtracJSONFileds,但那样也会引发错误,如HTTP 415 Unsupported Media Type。但我预先在tRESTClient的设置中添加了内容类型。 – user3114967

+0

在我的文章中,我添加了URL的输出值。这不是一种XML格式。 – user3114967

回答

1

这是抛出错误,因为响应是一个JSON数组而不是简单的json对象。

您可以将响应存储到json文件中。使用tFileInputJSON读取文件,然后使用tExtractJSONFields提取值。

下面是示例作业(I已经在上面的示例数据使用)

sample job

[样本作业][1]

+0

将结果存储在json输出文件中后,尝试像上面的例子。但它抛出一个错误,无法解析JSON文件:C:/Desktop/Output.json – user3114967

+0

如果我选择Read By作为JsonPath没有循环,则生成一条记录。但我需要获得所有的价值。 19个计数 – user3114967

+0

你得到19个记录在一个JSONArray或19个不同的JSONArray? –

0

由于其不一个JSONObject 它是一种JSONArray

穿戴循环路径在tExtractJsonfield组件中查询

相关问题