我有一个查询涉及如何使用groovy获取JSR223 Post处理器中json数组的长度。 " outBound"内有2个信息块。阵列。我需要得到阵列的长度" outBound"这样我就可以将长度放在for循环中。我还想得到一个信息json数组(原样),其中包含参数" taxType":" GST"。例如:这里第二个信息有GST值..所以想要获取第二个信息json数组
$this->load->library('excel');
$file_name = 'Demo';
$arrHeader = array('Name', 'Mobile');
$arrRows = array(0=>array('Name'=>'Jayant','Mobile'=>54545), 1=>array('Name'=>'Jayant1', 'Mobile'=>44454), 2=>array('Name'=>'Jayant2','Mobile'=>111222), 3=>array('Name'=>'Jayant3', 'Mobile'=>99999));
$this->excel->getActiveSheet()->fromArray($arrHeader,'','A1');
$this->excel->getActiveSheet()->fromArray($arrRows);
header('Content-Type: application/vnd.ms-excel'); //mime type
header('Content-Disposition: attachment;filename="'.$file_name.'"'); //tell browser what's the file name
header('Cache-Control: max-age=0'); //no cache
$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
$objWriter->save('php://output');
答案 0 :(得分:0)
我不太确定我理解,但如果我这样做,那就是你需要的:
def res = new groovy.json.JsonSlurper().parseText(json)
def outBound = res.details[0].outBound
println outBound.size()
println groovy.json.JsonOutput.toJson(outBound.find { it.info.gstAmount?.taxType == "GST" })
json
是持有json的String
实例。
逐行:
outBound
数组details
数组
outBound
数组outBound
属性为" GST" info.gstAmout.taxType
数组的第一个元素格式化回Json。 (gstAmount
之后的问号优雅地处理可能缺少该财产的情况)