ECMAscript 遍历属性json的数据

遍历属性json的数据

 1 var flowFile = session.get();
 2 if(flowFile != null) {
 3     try {
 4         var attrName = flowFile.getAttribute('循环属性名')
 5         var listStr = flowFile.getAttribute(attrName)
 6         var index = flowFile.getAttribute(attrName+'.Index')
 7         var saveAttrName = flowFile.getAttribute('存储属性名')
 8         if(index == null){
 9             index = 0;
10         }
11         var list = JSON.parse(listStr)
12         var len = list.length;
13         var res = {};
14         if(index < len){
15             res = list[index]
16         }
17         flowFile = session.putAttribute(flowFile, attrName+'.Index', ++index)
18         flowFile = session.putAttribute(flowFile, attrName+'.Length', len)
19         flowFile = session.putAttribute(flowFile, saveAttrName,res)
20         session.transfer(flowFile, REL_SUCCESS)
21     } catch(e) {
22         session.transfer(flowFile, REL_FAILURE)
23     }
24 }

 

判断最后一个

 1 var flowFile = session.get();
 2 if(flowFile != null) {
 3     try {
 4         var attrName = flowFile.getAttribute('循环属性名')
 5         var index = parseInt(flowFile.getAttribute(attrName+'.Index'),10)
 6         var len = parseInt(flowFile.getAttribute(attrName+'.Length'),10)
 7         if(index <= len){
 8             session.transfer(flowFile, REL_FAILURE)
 9         }else{
10             session.transfer(flowFile, REL_SUCCESS)
11         }
12     } catch(e) {
13         session.transfer(flowFile, REL_FAILURE)
14     }
15 }

 

posted @ 2021-07-22 14:30  木章  阅读(57)  评论(0编辑  收藏  举报