Java 在Talend 5.5中使用正则表达式的jsonpath
我有一个json字符串: 我想提取编号节点后面的所有ID:Java 在Talend 5.5中使用正则表达式的jsonpath,java,regex,json,talend,jsonpath,Java,Regex,Json,Talend,Jsonpath,我有一个json字符串: 我想提取编号节点后面的所有ID:“0”,“1”,“2”…等等 通过使用jsonpath:$.response.data.0.id和get“15124”,我成功地获得了一个id。 但是我正在寻找一个jsonpath,它将提取Json字符串中的所有ID。 换句话说,这是扩展输出:15124,13498,14296,13364,14060,13672 这是我的Json字符串: { "response": { "code": 200, "msg": "Succe
“0”
,“1”
,“2”
…等等
通过使用jsonpath:$.response.data.0.id
和get“15124”
,我成功地获得了一个id。
但是我正在寻找一个jsonpath,它将提取Json字符串中的所有ID。
换句话说,这是扩展输出:15124
,13498
,14296
,13364
,14060
,13672
这是我的Json字符串:
{
"response": {
"code": 200,
"msg": "Success",
"data": {
"0": {
"id": "15124",
"name": " yoav (yoavshaki@yahoo.com) - 301519506662355",
"network_id": 1,
"network_type": "Facebook",
"currency": "USD",
"currency_info": {
"prefix": "$",
"postfix": "",
"name": "US Dollars"
},
"timezone": {
"id": 139,
"code": "IST",
"region": "Asia",
"locality": "Jerusalem",
"offset": 3,
"facebook_code": 70
}
},
"1": {
"id": "13498",
"name": "(Not in used) Daniel - 30138444",
"network_id": 1,
"network_type": "Facebook",
"currency": "USD",
"currency_info": {
"prefix": "$",
"postfix": "",
"name": "US Dollars"
},
"timezone": {
"id": 92,
"code": "PST",
"region": "America",
"locality": "Los_Angeles",
"offset": -7,
"facebook_code": 1
}
},
"2": {
"id": "14296",
"name": "Daniel - ComeOn (bingocafe@walla.com - 1375713835981039)",
"network_id": 1,
"network_type": "Facebook",
"currency": "USD",
"currency_info": {
"prefix": "$",
"postfix": "",
"name": "US Dollars"
},
"timezone": {
"id": 92,
"code": "PST",
"region": "America",
"locality": "Los_Angeles",
"offset": -7,
"facebook_code": 1
}
},
"3": {
"id": "13364",
"name": "Erez - 116060088528093",
"network_id": 1,
"network_type": "Facebook",
"currency": "USD",
"currency_info": {
"prefix": "$",
"postfix": "",
"name": "US Dollars"
},
"timezone": {
"id": 92,
"code": "PST",
"region": "America",
"locality": "Los_Angeles",
"offset": -7,
"facebook_code": 1
}
},
"4": {
"id": "14060",
"name": "Erez - NordicBet (gianniciano82@gmail.com - 105134566315107)",
"network_id": 1,
"network_type": "Facebook",
"currency": "USD",
"currency_info": {
"prefix": "$",
"postfix": "",
"name": "US Dollars"
},
"timezone": {
"id": 139,
"code": "IST",
"region": "Asia",
"locality": "Jerusalem",
"offset": 3,
"facebook_code": 70
}
},
"5": {
"id": "13672",
"name": "Erez - alon.dan - 1378526859026272",
"network_id": 1,
"network_type": "Facebook",
"currency": "USD",
"currency_info": {
"prefix": "$",
"postfix": "",
"name": "US Dollars"
},
"timezone": {
"id": 92,
"code": "PST",
"region": "America",
"locality": "Los_Angeles",
"offset": -7,
"facebook_code": 1
}
}
}
}
}
谢谢所有的帮助 是将java对象转换为json字符串的好方法,反之亦然
- 要将json转换为java对象,请使用:
- 要将java对象转换为json字符串,请使用:
BufferedReader reader = new BufferedReader(new FileReader(new File("resources/json.txt")));
Gson gson = new Gson();
Type type = new TypeToken<Map<String, Map<String, Object>>>() {}.getType();
Map<String, Map<String, Object>> map = gson.fromJson(reader, type);
Map<String, Map<String, Object>> innerMap = (Map<String, Map<String, Object>>) map.get("response").get("data");
for (String key : innerMap.keySet()) {
System.out.println("key:" + key + " id:" + innerMap.get(key).get("id"));
}
谢谢你的回答
$.response.data.*.id
确实有效 您是否尝试过$.response.data.*.id
?@nerdwaller否,这是Java库的语法。您尝试过。。。什么,到目前为止?请不要到这里来让其他人为您编写代码。$.response.data.*.id
将起作用。您应该在评论中感谢用户,而不是发布新的答案。
key:0 id:15124
key:1 id:13498
key:2 id:14296
key:3 id:13364
key:4 id:14060
key:5 id:13672