Javascript 如何使用linq.js查询Json对象?
我正在将xml文件转换为Json格式,我正在尝试使用 到目前为止,这就是我所做的:Javascript 如何使用linq.js查询Json对象?,javascript,json,linq.js,Javascript,Json,Linq.js,我正在将xml文件转换为Json格式,我正在尝试使用 到目前为止,这就是我所做的: var queryResult = linq.from(result).where( function(x){ return x.key == "bpmn2:definitions" } ).select(function(x) { return x } ).toArray(); 我得到了以下json: [ { key: 'bpmn2:definitions', value: { '
var queryResult = linq.from(result).where( function(x){ return x.key == "bpmn2:definitions" } ).select(function(x) { return x } ).toArray();
我得到了以下json:
[ { key: 'bpmn2:definitions',
value:
{ '$': [Object],
'bpmn2:message': [Object],
'bpmn2:interface': [Object],
process: [Object] } } ]
如何仅通过修改名为进程的嵌入对象的where子句就可以进入相同的查询
编辑:
到目前为止,我已经做到了:
var queryResult = linq.from(result).where( function(x){ return x.key == "bpmn2:definitions" } ).select(function(x) { return x.value.process } ).toArray();
我得到
[ [ { '$': [Object],
'bpmn2:process': [Object],
'bpmndi:BPMNDiagram': [Object] } ] ]
如何在上述同一查询中访问bpmn2:process
谢谢你这样的帮助?我想这就是你要问的
var queryResult = linq.from(result).where( function(x){ return x.key == "bpmn2:definitions" } ).select(function(x) { return x.value.process } ).toArray();
谢谢Joe,我一分钟前刚刚得到了同样的结果,谢谢你的回答,如果你能看一下的话,那是正确的。我编辑了这个问题,我正试图详细说明一个更复杂的查询,对不起编辑。我这样做我觉得有点脏:linq.from(result)。where(function(x){return x.key==“bpmn2:definitions”})。选择(函数(x){return x.value.process[0][“bpmn2:process”]}).toArray();无论如何它都能工作!感谢您的帮助help@Pedro作为旁注。我不会使用x.key==“bpmn2:definitions”,因为每次比较都会执行类型转换。请使用严格的相等比较器“==”而不是“==”。“==”只有当你比较一个像2这样的整数,你才不在乎2是否也是一个“2”时,才可以使用