本文整理汇总了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;
}
示例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);
}
}
}
}
}
示例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);
}
}
}
示例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);
};
}
示例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();
}
}
示例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);
}
}
示例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;
}
示例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();
}
}
示例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);
}
示例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);
}
示例11: FromJsonStep
import groovy.json.JsonSlurper; //导入依赖的package包/类
@DataBoundConstructor
public FromJsonStep(String jsonString) {
jsonParser = new JsonSlurper();
this.setJsonString(jsonString);
}
示例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;
}
示例13: jsonParser
import groovy.json.JsonSlurper; //导入依赖的package包/类
public static Object jsonParser(String json){
return (new JsonSlurper()).parseText(json);
}
示例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));
}
示例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()));
}