Kettle解析JSON错误,We MUST have the same number of values for all paths,We can not find and data with path [$.
最近公司要从聚石塔上抽取数据,其中有JSON格式数据,所以学习一下Kettle解析JSON,碰到小小问题,记录一下:
(1)
2015/07/15 15:22:48 - trade_detail.0 - ERROR (version 5.4.0.1-130, build 1 from 2015-06-14_12-34-55 by buildguy) : Unexpected Error : org.pentaho.di.core.exception.KettleException:
2015/07/15 15:22:48 - trade_detail.0 - The data structure is not the same inside the resource! We found 2 values for json path [$..title], which is different that the number returned for path [$..buyer_alipay_no] (1 values). We MUST have the same number of values for all paths.
2015/07/15 15:22:48 - trade_detail.0 - ERROR (version 5.4.0.1-130, build 1 from 2015-06-14_12-34-55 by buildguy) : org.pentaho.di.core.exception.KettleException:
2015/07/15 15:22:48 - trade_detail.0 - The data structure is not the same inside the resource! We found 2 values for json path [$..title], which is different that the number returned for path [$..buyer_alipay_no] (1 values). We MUST have the same number of values for all paths.
2015/07/15 15:22:48 - trade_detail.0 -
原因是由于JSON嵌套内的对象还有同样的title,所以无法解析。
方法:
在外面这层用javascript解析,然后重命名,继续往下用JSON控件解析...
JAVASCRIPT代码:
var data = JSON.parse(trade);
var alipay_id = data.alipay_id;
var buyer_alipay_no = data.buyer_alipay_no;
var seller_nick = data.seller_nick;
var orders1 = data.orders;
var title1 = data.title;
var logistics_company1 = data.title;
这样只能解决2个同名的JSON结构,当JSON存在3个同名的,1个在外层,2个嵌套在不同的对象里面,还是会报错。
既然是path问题,那就看看是否可以修改path。
官网上又这样的路径,依样画葫芦,OK!
XPath | JSONPath | Description |
/ | $ | the root object/element |
. | @ | the current object/element |
/ | . or [] | child operator |
.. | n/a | parent operator |
// | .. | recursive descent. JSONPath borrows this syntax from E4X. |
* | * | wildcard. All objects/elements regardless their names. |
@ | n/a | attribute access. JSON structures don't have attributes. |
[] | [] | subscript operator. XPath uses it to iterate over element collections and for predicates. In Javascript and JSON it is the native array operator. |
| | [,] | Union operator in XPath results in a combination of node sets. JSONPath allows alternate names or array indices as a set. |
n/a | [start:end:step] | array slice operator borrowed from ES4. |
[] | ?() | applies a filter (script) expression. |
n/a | () | script expression, using the underlying script engine. |
() | n/a | grouping in Xpath |
XPath | JSONPath | Result |
/store/book/author |
$.store.book[*].author |
the authors of all books in the store |
//author |
$..author |
all authors |
/store/* |
$.store.* |
all things in store, which are some books and a red bicycle. |
/store//price |
$.store..price |
the price of everything in the store. |
//book[3] |
$..book[2] |
the third book |
//book[last()] |
$..book[(@.length-1)] $..book[-1:] |
the last book in order. |
//book[position()<3] |
$..book[0,1] $..book[:2] |
the first two books |
//book[isbn] |
$..book[?(@.isbn)] |
filter all books with isbn number |
//book[price<10] |
$..book[?(@.price<10)] |
filter all books cheapier than 10 |
//* |
$..* |
all Elements in XML document. All members of JSON structure. |
官网关于path的URL:http://wiki.pentaho.com/display/EAI/JSON+Input
根据官网提示链接到: http://goessner.net/articles/JsonPath/
(2)
2015/07/15 15:30:48 - trade_detail.0 - ERROR (version 5.4.0.1-130, build 1 from 2015-06-14_12-34-55 by buildguy) : Unexpected Error : org.pentaho.di.core.exception.KettleException:
2015/07/15 15:30:48 - trade_detail.0 - org.pentaho.di.core.exception.KettleException:
2015/07/15 15:22:48 - trade_detail.0 -
2015/07/15 15:22:48 - trade_detail.0 -
2015/07/15 15:22:48 - trade_detail.0 -We can not find and data with path [$..logistics_company]
原因:JSON中存在不完整的字段,无法解析。
方法:
1、用javascript脚本读取内容
2、勾选json控件-->内容-->设置忽视不完整的路径
(不过这个方式对嵌套多层的无效)
javascript脚本例子:
var json={"status":1,"info":"u83b7u53d6u6210u529f","data":[{ "name":"dingding","information":"电视迷","Region_id":"3","type":"1"},{"id":"5","name":"kenwong","information":"you are ok","Region_id":"5","type":"100"}]}
var data=json.data;
var str1 ="";
var str2 ="";
var str3 ="";
for(i=0;i<data.length;i++)
{
str1 += data[i].name +","
str2 += data[i].information +",";
str3 += data[i].id +",";
}
Kettle解析JSON错误,We MUST have the same number of values for all paths,We can not find and data with path [$.的更多相关文章
- kettle 利用 HTTP Client 获取猫眼电影API近期上映相关信息,并解析json
前言 Kettle 除了常规的数据处理之外,还可以模拟发送HTTP client/post ,REST client. 实验背景 这周二老师布置了一项实验: 建立一个转换,实现一个猫眼API热映电影的 ...
- JAVA简便解析json文件
JAVA简便解析json文件 首先放上我要解析的json文件: { "resultcode":"200", "reason":"S ...
- 使用Gson解析Json数组遇到的泛型类型擦除问题解决方法
谷歌Gson转换Json串有如下方法: public Object fromJson(String json, Type typeOfT);1可以使用它进行数组解析.如下,使用此方法解析Json串为类 ...
- json解析json字符串时候,数组必须对应jsonObjectArray,不能对应JsonObject。否则会解析错误。
json第三方解析json字符串时候,json数组必须对应jsonObjectArray,不能对应JsonObject.->只要是[]开头的都是json数组字符串,就要用jsonArray解析 ...
- Jquery.ajax报parseerror Invalid JSON错误的原因和解决方法:不能解析
(默认: 自动判断 (xml 或 html)) 请求失败时调用时间.参数有以下三个:XMLHttpRequest 对象.错误信息.(可选)捕获的错误对象.如果发生了错误,错误信息(第二个参数)除了得到 ...
- [转]javascript eval函数解析json数据时为什加上圆括号eval("("+data+")")
javascript eval函数解析json数据时为什么 加上圆括号?为什么要 eval这里要添加 “("("+data+")");//”呢? 原因在于: ...
- js中eval详解,用Js的eval解析JSON中的注意点
先来说eval的用法,内容比较简单,熟悉的可以跳过eval函数接收一个参数s,如果s不是字符串,则直接返回s.否则执行s语句.如果s语句执行结果是一个值,则返回此值,否则返回undefined. 需要 ...
- VBA中使用JavaScript脚本语言解析JSON数据
JSON:JavaScript 对象表示法(JavaScript Object Notation) 和xml相似,都是文本形式(保存在文本文件中或字符串等形式),比如: jsstr = {" ...
- 更好更快更高效解析JSON说明
现在来一个实例解析类,直接就把解析JSON到QVariant去了.唯一不足的是没有搞错误处理,具体方法也请各位自行参考json-c的发行文档,这样比较方便叙述,STL或者Boost我都没有认真接触过, ...
随机推荐
- Centos7卸载FastDFS6.1卸载(六)
今天由于安装了高版本的fastdfs,与nginx不兼容,因此要卸载掉,重新安装. 转载:http://www.leftso.com/blog/244.html ) 停止服务 [root@bogon ...
- 【HDOJ6627】equation(模拟)
题意:给定n,整数序列a和b,整数C,求所有成立的x n<=1e5,1<=a[i]<=1e3,-1e3<=b[i]<=1e3,1<=C<=1e9 思路: 大概 ...
- ORACLE修改表字段顺序
1.若'GYZL_BZPWL_TB' 为要修改的表名,注意表名一定要大写!此句可以获取表的id.select object_id from all_objects where object_name= ...
- 51nod1600 Simple KMP
题目描述 对于一个字符串|S|,我们定义fail[i],表示最大的x使得S[1..x]=S[i-x+1..i],满足(x<i) 显然对于一个字符串,如果我们将每个0<=i<=|S|看 ...
- 学习日记10、easyui编辑器combobox绑定数据的两种方式
1.数据本地绑定 var card = [{ "value": "正常", "text": "正常" }, { &quo ...
- [CSP-S模拟测试]:数论(数学)
题目传送门(内部题11) 输入格式 第一行,三个整数$T,K,M$,分别代表数据组数.良好标准和整数范围.接下来$T$行,每行一个整数$n_i$,代表一个询问. 输出格式 输出$T$行,在第$i$行对 ...
- php的URL查询字符串解析函数
URL查询字符串格式:Data[650][BLN]=40002307312&Data[650][Status]=電聯無人接聽. 解析这种数据使用函数:parse_str(). parse_st ...
- php.ini 配置项详解
本文主要对php.ini文件进行详细的解释 engine = On ——> 在apache下启用php语言引擎 short_open_tag = Off ——> 是否开启段标签 若php ...
- JavaScript 获取随机整数
Math.random()方法会返回介于 0(包含) ~ 1(不包含) 之间的一个随机数 假如想要拿到0-10之间的数,只需要将该方法的值*10 即Math.random()*10: 假如想要拿到0- ...
- 【ABAP系列】SAP ABAP-模块 字符串操作基础知识
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP-模块 字符串操 ...