[英]How to get the value of “name” field from the json using jsonpath expression
I want to get the value against "name" field from the below json. 我想从下面的json获取针对“名称”字段的值。 I tried using the tools http://jsonpathfinder.com/ and http://jsonpath.com/ ? 我尝试使用工具http://jsonpathfinder.com/和http://jsonpath.com/吗? I am using http://jsonpath.herokuapp.com/ to verify if the expression path is correct, but it always returns me as an incorrect expression. 我正在使用http://jsonpath.herokuapp.com/来验证表达式路径是否正确,但是它始终以错误的表达式返回我。
{
"data" : {
"PensionRetriever(Customer=ABC, typeInfo=valid)" : {
"name" : "lifeInsurance",
"created_at" : 1552297775384,
"attributes" : [ {
"id" : "4044da39-c23b-4588-b6c4-975ce02e7cb2",
"name" : "lifeInsurance",
"created_at" : 1552297775384
}]
}
}
}
I tried with $.data["PensionRetriever(Customer=ABC, typeInfo=valid)"].name
, but this seems incorrect. 我尝试使用$.data["PensionRetriever(Customer=ABC, typeInfo=valid)"].name
,但这似乎不正确。 Can you please tell me now to get the value of "name" , ie, lifeInsurance 您现在可以告诉我获取“名称”的值,即lifeInsurance吗
Use single quoted rather than double quoted names in the JSONPath expression, ie 在JSONPath表达式中使用单引号而不是双引号,即
$.data['PensionRetriever(Customer=ABC, typeInfo=valid)'].name
Using the online evaluators on http://jsonpath.herokuapp.com/ , the usually reliable Jayway fails, apparently unable to digest the name 'PensionRetriever(Customer=ABC, typeInfo=valid)'
. 使用http://jsonpath.herokuapp.com/上的在线评估程序,通常可靠的Jayway失败,显然无法消化名称'PensionRetriever(Customer=ABC, typeInfo=valid)'
。 That's a Jayway bug. 那是Jayway的错误。 But Goessner succeeds, returning the expected 但Goessner成功,返回了预期
[ "lifeInsurance" ]
var path = $.JSONPath({data: json, keepHistory: false}); var path = $ .JSONPath({data:json,keepHistory:false}); var test=path.query('$.data.PensionRetriever(Customer=ABC,typeInfo=valid).name'); var test = path.query('$。data.PensionRetriever(Customer = ABC,typeInfo = valid).name');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.