在JAVA中将两个字符串数组合并为JSON格式
我有两个阵列:
String[] COLUMN_NAMES = { "row_number", "column_name", "column_value_string", "column_value_float", "blockId", "pipelineId" };
String[] Values = { "1", "Output", "Valid", "", "123sde-dfgr", "pipeline-sde34" };
其中,我需要的输出是json格式(将值数组中的空值替换为输出中的null):
{
"row_number": 1,
"column_name": "output",
"column_value_string": "Valid",
"column_value_float": null,
"blockId": "123sde-dfgr",
"pipelineId": "pipeline-sde34"
}
代码如下:
Map<String,String> result = IntStream.range( 0,COLUMN_NAMES.length ).boxed()
.collect( Collectors.toMap( i->COLUMN_NAMES[i], i->Values[i] ) );
# 1 楼答案