Groovy从字符串创建2个地图的列表

时间:2018-08-06 12:16:32

标签: string list dictionary groovy

嗨,我有这个String,其中包含List of 2 strings。然后,这些2 strings包含2 maps

示例def listStr = '["{"isReal":true,"area":"a"}","{"isRefundable":false,"area":"b"}"]';

如何从2张地图的字符串列表中获取?

结果[{isReal=true},{isRefundable=false}]

1 个答案:

答案 0 :(得分:0)

RecurringJobManager可以为您完成这项工作:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IRecurringJobManager recurringJobs)
   {
       //Access To HangFire dashboard : http://app_hostname/hangfire
        app.UseHangfireDashboard();
        app.UseHangfireServer();
       //....
       //....
       app.UseMvc(); 
       //....
       //....
       recurringJobs.AddOrUpdate("FixOrderJob", Job.FromExpression<IOrderFixerService>(x => x.FixLatestUnknownOrder()), Cron.MinuteInterval(1));
    }

如果要在输出中包含地图,则可以像这样转换JsonSlurper

import groovy.json.JsonSlurper

JsonSlurper js = new JsonSlurper()
def listStr = '["{"isReal":true}","{"isRefundable":false}"]'
def res = []
listStr.eachMatch( /"(\{[^\{\}]+\})"/ ){ res << js.parseText( it[ 1 ] ) }
assert [[isReal:true], [isRefundable:false]] == res