当前位置: 首页>>代码示例>>Java>>正文


Java JsonSlurper类代码示例

本文整理汇总了Java中groovy.json.JsonSlurper的典型用法代码示例。如果您正苦于以下问题:Java JsonSlurper类的具体用法?Java JsonSlurper怎么用?Java JsonSlurper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JsonSlurper类属于groovy.json包,在下文中一共展示了JsonSlurper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildNotifyJson

import groovy.json.JsonSlurper; //导入依赖的package包/类
private String buildNotifyJson( @Nonnull final AbstractBuild build,
                                @Nonnull final Map<String,?> env )
{
    Map<String,?> binding = new HashMap<String, Object>(){{
       put( "jenkins", notNull( Jenkins.getInstance(), "Jenkins instance" ));
       put( "build",   notNull( build, "Build instance" ));
       put( "env",     notNull( env, "Build environment" ));
    }};

    String json     = null;
    String template = "<%\n\n" + JSON_FUNCTION + "\n\n%>\n\n" +
                      notBlank( notifyTemplate, "Notify template" );

    try
    {
        json = notBlank( new SimpleTemplateEngine( getClass().getClassLoader()).
                         createTemplate( template ).
                         make( binding ).toString(), "Payload JSON" ).trim();

        Asserts.check(( json.startsWith( "{" ) && json.endsWith( "}" )) ||
                      ( json.startsWith( "[" ) && json.endsWith( "]" )),
                      "Illegal JSON content: should start and end with {} or []" );

        Asserts.notNull( new JsonSlurper().parseText( json ), "Parsed JSON" );
    }
    catch ( Exception e )
    {
        throwError(( json == null ?
            String.format( "Failed to parse Groovy template:%s%s%s",
                           LINE, template, LINE ) :
            String.format( "Failed to validate JSON payload (check with http://jsonlint.com/):%s%s%s",
                           LINE, json, LINE )), e );
    }

    return json;
}
 
开发者ID:evgeny-goldin,项目名称:jenkins-notify-plugin,代码行数:37,代码来源:NotifyRecorder.java

示例2: addMetaCols

import groovy.json.JsonSlurper; //导入依赖的package包/类
public static void addMetaCols(Map rowMap){
	//add 20180111 ninghao
	if(rowMap==null){
		return;
	}
	
	List<String> metaContentNameList=checkMetaContentName(rowMap);
	for(String metaContentName:metaContentNameList){
		String metaContentNamePrefix=metaContentName.replace("meta_content", "");
		String meta_content=(String) rowMap.get(metaContentName);
		if(meta_content==null || "".equals(meta_content)){
			continue;
		}
		Map metaMap=(Map) new JsonSlurper().parseText(meta_content);
		if(metaMap!=null){
			Set<String> keySet=metaMap.keySet();
			for(String key:keySet){
				Object obj=metaMap.get(key);
				if(obj instanceof Map || obj instanceof List){
					//continue;
				}
				String nkey=metaContentNamePrefix+key;
				if(!rowMap.containsKey(nkey)){
					rowMap.put(nkey, obj);
				}
			}
		
		}
	}

}
 
开发者ID:jeffreyning,项目名称:nh-micro,代码行数:32,代码来源:CheckModelTypeUtil.java

示例3: changeJsonMap

import groovy.json.JsonSlurper; //导入依赖的package包/类
public void changeJsonMap(Map infoMap){
	Set<String> keySet=infoMap.keySet();
	for(String key:keySet){
		if(key.endsWith("_json")){
			String val=(String) infoMap.get(key);
			Object obj=new JsonSlurper().parseText(val);
			infoMap.put(key, obj);
		}
	}
}
 
开发者ID:jeffreyning,项目名称:nh-micro,代码行数:11,代码来源:MicroServiceTemplateSupport.java

示例4: gameInfo

import groovy.json.JsonSlurper; //导入依赖的package包/类
public void gameInfo(Closure<?> closure) {
    this.gameInfo = closure;
    helper.details = game -> {
        System.out.println("game is " + game);
        Closure<?> buildClosure = (Closure<?>) closure.call(game);

        JsonBuilder builder = new JsonBuilder();
        builder.call(buildClosure);

        String result = builder.toPrettyString();
        System.out.println(result);
        JsonSlurper slurper = new JsonSlurper();
        return slurper.parseText(result);
    };
}
 
开发者ID:Zomis,项目名称:flexgame-server,代码行数:16,代码来源:GroovyGames.java

示例5: parse

import groovy.json.JsonSlurper; //导入依赖的package包/类
private static Object parse(CloseableHttpResponse resp) throws IOException{
	try{
		return (new JsonSlurper()).parse((new InputStreamReader(resp.getEntity().getContent())));
	} finally{
		resp.close();
	}
}
 
开发者ID:GoogleCloudPlatform,项目名称:jenkernetes,代码行数:8,代码来源:KubernetesClient.java

示例6: handleWebSocketFrame

import groovy.json.JsonSlurper; //导入依赖的package包/类
private void handleWebSocketFrame(ChannelHandlerContext ctx, TextWebSocketFrame frame) {
    // System.out.println("Received: " + frame.text());
    JsonSlurper slurper = new JsonSlurper();
    Object o = slurper.parseText(frame.text());
    if (!(o instanceof Map<?, ?>)) return;
    Map<?, ?> msg = (Map<?, ?>) o;
    if (!msg.containsKey("type")) return;
    Object typeO = msg.get("type");
    if (!(typeO instanceof String)) return;
    String type = (String) typeO;
    
    if (type.equals("rq")) {
        // Received a request
        // Need id, method name and data
        if (!msg.containsKey("id") || !msg.containsKey("method") || !msg.containsKey("data")) return;
        Object idObj = msg.get("id");
        long id;
        if (idObj instanceof Integer) {
            id = (Integer) idObj;
        }
        else if (idObj instanceof Long) {
            id = (Long) idObj;
        }
        else return;
        Object methodObj = msg.get("method");
        if (!(methodObj instanceof String)) return;
        String method = (String) methodObj;
        Object dataObj = msg.get("data");
        Map<?, ?> data;
        if (dataObj instanceof Map<?, ?>) data = (Map<?, ?>) dataObj;
        else data = null;
        handleRequest(ctx, id, method, data);
    }
}
 
开发者ID:Matthias247,项目名称:adalightserver,代码行数:35,代码来源:HttpServer.java

示例7: refreshTokens

import groovy.json.JsonSlurper; //导入依赖的package包/类
public boolean refreshTokens(String refreshToken) {
    if (refreshToken == null) {
        return false;
    }
    String postContent = "";
    try {
        URL tokenURL = new URL("https://coinbase.com/oauth/token");

        HttpURLConnection uc = (HttpURLConnection) tokenURL.openConnection();
        uc.setRequestMethod("POST");
        uc.setDoOutput(true);
        postContent = "grant_type=refresh_token" +
                "&refresh_token=" + refreshToken +
                "&redirect_uri=" + CALLBACK_URL +
                "&client_id=" + COINBASE_CLIENT_ID +
                "&client_secret=" + COINBASE_CLIENT_SECRET;
        uc.getOutputStream().write(postContent.getBytes());
        uc.connect();

        JsonSlurper slurper = new JsonSlurper();
        Map m = (Map) slurper.parse(new InputStreamReader(uc.getInputStream())); // TODO cleanup

        long expire = System.currentTimeMillis() + ((((Number)m.get("expires_in")).longValue()*1000));

        saveToken((String) m.get("access_token"), "access_token");
        saveToken((String) m.get("refresh_token"), "refresh_token");
        saveToken(Long.toString(expire), "expire");

        Platform.runLater(() -> accessToken.setValue((String) m.get("access_token")));
        return true;
    } catch (IOException e) {
        Platform.runLater(() -> accessToken.setValue(""));
        System.out.println(postContent);
        e.printStackTrace();
    }

    return false;
}
 
开发者ID:shemnon,项目名称:FollowTheBitcoin,代码行数:39,代码来源:CoinBaseOAuth.java

示例8: requestTokens

import groovy.json.JsonSlurper; //导入依赖的package包/类
private void requestTokens(String code) {
    try {
        URL tokenURL = new URL("https://coinbase.com/oauth/token");

        HttpURLConnection uc = (HttpURLConnection) tokenURL.openConnection();
        uc.setRequestMethod("POST");
        uc.setDoOutput(true);

        String postContent = "grant_type=authorization_code" +
                "&code=" + code +
                "&redirect_uri=" + CALLBACK_URL +
                "&client_id=" + COINBASE_CLIENT_ID +
                "&client_secret=" + COINBASE_CLIENT_SECRET;
        uc.getOutputStream().write(postContent.getBytes());
        uc.connect();

        JsonSlurper slurper = new JsonSlurper();
        Map m = (Map) slurper.parse(new InputStreamReader(uc.getInputStream())); // TODO cleanup

        long expire = System.currentTimeMillis() + ((((Number)m.get("expires_in")).longValue()*1000));

        saveToken((String) m.get("access_token"), "access_token");
        saveToken((String) m.get("refresh_token"), "refresh_token");
        saveToken(Long.toString(expire), "expire");

        Platform.runLater(() -> accessToken.setValue((String) m.get("access_token")));
    } catch (Exception e) {
        Platform.runLater(() -> accessToken.setValue(""));
        e.printStackTrace();
    }
}
 
开发者ID:shemnon,项目名称:FollowTheBitcoin,代码行数:32,代码来源:CoinBaseOAuth.java

示例9: vega

import groovy.json.JsonSlurper; //导入依赖的package包/类
default Object vega(String content) {
    JsonSlurper jsonSlurper = new JsonSlurper();
    Object json = jsonSlurper.parseText(content);
    return displayMimetype("application/vnd.vega.v2+json", json);
}
 
开发者ID:scijava,项目名称:scijava-jupyter-kernel,代码行数:6,代码来源:NotebookService.java

示例10: vegalite

import groovy.json.JsonSlurper; //导入依赖的package包/类
default Object vegalite(String content) {
    JsonSlurper jsonSlurper = new JsonSlurper();
    Object json = jsonSlurper.parseText(content);
    return displayMimetype("application/vnd.vegalite.v1+json", json);
}
 
开发者ID:scijava,项目名称:scijava-jupyter-kernel,代码行数:6,代码来源:NotebookService.java

示例11: FromJsonStep

import groovy.json.JsonSlurper; //导入依赖的package包/类
@DataBoundConstructor
public FromJsonStep(String jsonString) {
    jsonParser = new JsonSlurper();
    this.setJsonString(jsonString);
}
 
开发者ID:joostvdg,项目名称:json-helper-jenkins-pipeline-plugin,代码行数:6,代码来源:FromJsonStep.java

示例12: adapter

import groovy.json.JsonSlurper; //导入依赖的package包/类
/**
 * responder closure call is delayed until stub server calls back
 */
public TestCaseAdapterStub adapter(Closure<Boolean> matcher, Closure<String> responder, Closure<?> init) throws TestException {
    final TestCaseAdapterStub adapterStub = new TestCaseAdapterStub(matcher, responder);
    if (init != null) {
        init.setResolveStrategy(Closure.DELEGATE_FIRST);
        init.setDelegate(adapterStub);
        init.call();
    }
    if (responder == null) {
        adapterStub.setResponder(new Closure<String>(this, adapterStub) {
            @Override
            public String call(Object request) {
                // binding for request
                final TestCaseRun testCaseRun = getTestCaseRun();
                if (adapterStub.getResponse().indexOf("${") >= 0) {
                    try {
                        Binding binding = getBinding();
                        if (request.toString().startsWith("{")) {
                            Object req = new JsonSlurper().parseText(request.toString());
                            binding.setVariable("request", req);
                        }
                        else {
                            GPathResult gpathRequest = new XmlSlurper().parseText(request.toString());
                            binding.setVariable("request", gpathRequest);
                        }
                        CompilerConfiguration compilerCfg = new CompilerConfiguration();
                        compilerCfg.setScriptBaseClass(DelegatingScript.class.getName());
                        GroovyShell shell = new GroovyShell(TestCaseScript.class.getClassLoader(), binding, compilerCfg);
                        shell.setProperty("out", testCaseRun.getLog());
                        DelegatingScript script = (DelegatingScript) shell.parse("return \"\"\"" + adapterStub.getResponse() + "\"\"\"");
                        script.setDelegate(TestCaseScript.this);
                        return script.run().toString();
                    }
                    catch (Exception ex) {
                        getTestCaseRun().getLog().println("Cannot perform stub substitutions for request: " + request);
                        ex.printStackTrace(getTestCaseRun().getLog());
                    }
                }
                return adapterStub.getResponse();
            }
        });
    }
    return adapterStub;
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:47,代码来源:TestCaseScript.java

示例13: jsonParser

import groovy.json.JsonSlurper; //导入依赖的package包/类
public static Object jsonParser(String json){
  return (new JsonSlurper()).parseText(json);
}
 
开发者ID:detectiveframework,项目名称:detective,代码行数:4,代码来源:Detective.java

示例14: doExecute

import groovy.json.JsonSlurper; //导入依赖的package包/类
@Override
protected void doExecute(Parameters config, Parameters output) {
  String json = this.readAsString(config, "jsoninput", null, false, "jsoninput is missing");
  output.put("json", new JsonSlurper().parseText(json));
}
 
开发者ID:detectiveframework,项目名称:detective,代码行数:6,代码来源:JsonBuilderTask.java

示例15: json

import groovy.json.JsonSlurper; //导入依赖的package包/类
/**
 * Standard parser for json responses.
 *
 * @param fromServer Backend indenpendent representation of data returned from http server
 * @return Body of response
 */
public static Object json(final ChainedHttpConfig config, final FromServer fromServer) {
    return new JsonSlurper().parse(new InputStreamReader(fromServer.getInputStream(), fromServer.getCharset()));
}
 
开发者ID:http-builder-ng,项目名称:http-builder-ng,代码行数:10,代码来源:NativeHandlers.java


注:本文中的groovy.json.JsonSlurper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。